Wednesday, July 31, 2013

WordPress function to check if the current post is a custom post type

WordPress function to check if the current post is a custom post type


Just paste this code into your functions.php file:


function is_custom_post_type() {
    global $wp_query;
       
    $post_types = get_post_types(array('public'   => true,'_builtin' => false),'names','and');
   
    foreach ($post_types  as $post_type ) {
        if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
            return true;
        } else {
            return false;
        }
    }
}

Once complete, we can use the function as display below.

P.S. : function can be used outside the loop:

if (is_custom_post_type()) {
    //Current post is a custom post type
}

Saturday, June 1, 2013

How to automatically insert a list of related articles below the post

In wordpress When a reader finished reading one of your blog posts, you can suggesting him to read other article that he might like as well? Here is a quick solution to automatically display related posts (based on category) below the current post

First, you have to  paste the code below into the functions.php file from your theme.

// "More from This Category" list by Barış Ünver @ Wptuts+
function wptuts_more_from_cat( $title = "More From This Category:" ) {
    global $post;
    // We should get the first category of the post
    $categories = get_the_category( $post->ID );
    $first_cat = $categories[0]->cat_ID;
    // Let's start the $output by displaying the title and opening the <ul>
    $output = '<div id="more-from-cat"><h3>' . $title . '</h3>';
    // The arguments of the post list!
    $args = array(
        // It should be in the first category of our post:
        'category__in' => array( $first_cat ),
        // Our post should NOT be in the list:
        'post__not_in' => array( $post->ID ),
        // ...And it should fetch 5 posts - you can change this number if you like:
        'posts_per_page' => 5
    );
    // The get_posts() function
    $posts = get_posts( $args );
    if( $posts ) {
        $output .= '<ul>';
        // Let's start the loop!
        foreach( $posts as $post ) {
            setup_postdata( $post );
            $post_title = get_the_title();
            $permalink = get_permalink();
            $output .= '<li><a href="' . $permalink . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a></li>';
        }
        $output .= '</ul>';
    } else {
        // If there are no posts, we should return something, too!
        $output .= '<p>Sorry, this category has just one post and you just read it!</p>';
    }
    // Let's close the <div> and return the $output:
    $output .= '</div>';
    return $output;
}
 
 
 
Now open your single.php file in theme folder and call the function as describe below, where you'd like to display the related posts:

<?php echo wptuts_more_from_cat( 'More From This Category:' ); ?>
 

Friday, April 26, 2013

Exclude certain categories from being displayed in Wordpress

Exclude certain categories from being displayed in Wordpress

Thre are two ways to hide posts from certain categories to be displayed on the wordpress blog. You can either put this code inside the loop

    <?php  
    if ( have_posts() ) : query_posts($query_string .'&cat=-1,-2'); while ( have_posts() ) : the_post(); 
    ?> 
         

or you van use the plugin "Advanced Category Excluder" from wordpress plugin directory.


Add SVG upload support to WordPress blog

How to add SVG upload support to your WordPress blog

The WordPress uploader generally do not support the SVG format by default. But this file format is becoming quite popular nowadays, Thee simple example can guide you to add SVG upload to your WordPress install.

You have to simply just add the code below to your functions.php file. After that SVG upload will be supported autometically once the file is saved.

add_filter('upload_mimes', 'my_upload_mimes');

function my_upload_mimes($mimes = array()) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}


Wednesday, April 10, 2013

Redirect to post if search results only returns one post

In Wordpress when a visitor search your website using WordPress built-in search engine function, the search results are displayed as a list. The following functionality can improve the search engine by automatically redirecting the visitor to the post if there is only one post is found by WordPress search engine.


You need to just paste the following code into the functions.php file:

add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
    if (is_search()) {
        global $wp_query;
        if ($wp_query->post_count == 1) {
            wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
        }
    }
}

Friday, April 5, 2013

How to add hook in PrestaShop 1.5

How to add hook in PrestaShop 1.5

Sometimes we need to add custom hook in prestashop
The process of Hook adding in FrontController.php in PrestaShop 1.5 is different from the other previous version of prestashop like PreataShop 1.4 but for database and installing module parts are still the same way as it before.

1. Open “FrontController.php” from /override/classes/controller/
Default file is looks like this

<?php
 
class FrontController extends FrontControllerCore
{
 
}
 
2. Then, add this following code from main FrontController.php
 
<?php
 
class FrontController extends FrontControllerCore
{
    public function initContent()
    {
        $this->process();
        if (!isset($this->context->cart))
                $this->context->cart = new Cart();
        if ($this->context->getMobileDevice() == false) {
            // These hooks aren't used for the mobile theme.
            // Needed hooks are called in the tpl files.
            if (!isset($this->context->cart))
                $this->context->cart = new Cart();
            $this->context->smarty->assign(array(
                /* === START: DO NOT TOUCH IT */
                'HOOK_HEADER' => Hook::exec('displayHeader'),
                'HOOK_TOP' => Hook::exec('displayTop'),
                'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
                'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
                /* === END: DO NOT TOUCH IT */
                 
                /* === START: ADD HOOK | EXAMPLE */
                'HOOK_MY_USER' => Module::hookExec('myUser'),
                'HOOK_MY_CATEGORIES' => Module::hookExec('myCategories'),
                'HOOK_SEARCH' => Module::hookExec('mySearch')
                /* === END: ADD HOOK | EXAMPLE */
            ));
        } else {
            $this->context->smarty->assign(array(
                'HOOK_MOBILE_HEADER' => Hook::exec('displayMobileHeader'),
            ));
        }
    }
}
 
Now save he file and its done.. 



 

How to change mail color in PrestaShop 1.5

How to change mail color in PrestaShop 1.5


Just follow the simple steps
Go to
1. Preferences -> Themes






Thenge change in the manner of the following way

Now
2. Save and Done!


Tuesday, April 2, 2013

How to activate link manager on WordPress 3.5 (and newer)

How to activate link manager on WordPress 3.5 (and newer)

The new WordPress version like 3.5 (and newer) , wordpress have left out the Link Manager facility from the admin area. In the following way we can bring it back!


You can just paste this code into your functions.php file and it will works

<?php

    //Activate the Link Manager built in to the WordPress admin
    add_filter( 'pre_option_link_manager_enabled', '__return_true' );

?>

How to directly include Typekit fonts on your WordPress theme

How to directly include Typekit fonts on your WordPress theme

How to directly include Typekit fonts on your WordPress theme

Typekit is a very useful service which allow us to use countless different fonts on our website or blog. Typekit provide a WordPress plugin by using this we can easily add their fonts to our WordPress site, but there are no built-in solution by which we can integrating Typekit fonts directly to your theme. Please following tricks can do so.

Edit the code below and update the .js file path on line 2. Then, simple paste it on your functions.php file. Save the file, and you're done!

function theme_typekit() {
    wp_enqueue_script( 'theme_typekit', '//use.typekit.net/xxxxxxx.js');
}
add_action( 'wp_enqueue_scripts', 'theme_typekit' );

function light_typekit_inline() {
  if ( wp_script_is( 'theme_typekit', 'done' ) ) { ?>
      <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<?php }
}
add_action( 'wp_head', 'theme_typekit_inline' );


Monday, March 25, 2013

How To Add HTML Links To Standard Prestashop E-Mail Messages

How To Add HTML Links To Standard Prestashop E-Mail Messages


Standard Prestashop order messages section settings do not allow us creating messages which would contain HTML links with clickable anchor texts. But if you want that feature there is still a workaround which you can use to add HTML links to your e-mail messages.

To do this it is necessary to override the method AdminOrderController.php PostProcess as follows:
$customer_message->message = htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8');


Change to
$customer_message->message = Tools::getValue('message');

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off