Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Common function used in WP theme

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 222
    Comment on it

    Some useful WP function for developing themes

    have_posts();

    This function check whether the current WordPress query has any results. This is a Boolean function, and returns either TRUE or FALSE.

    syntax is :

    if ( have_posts() ) :
        while ( have_posts() ) : the_post();
            // Your  code
        endwhile;
    else :
        echo 'Sorry, no posts were found';
    endif;

    query posts
    query_posts() is used to alter the main query that WordPress uses to display posts , So by using query_post() function you can pass additional parameter to query_post() function and display the post.

    Syntax-

    query_posts( array( 'category__and' => array(1,3), 'posts_per_page' => 2, 'orderby' => 'title', 'order' => 'DESC' ) );
    
    while ( have_posts() ) : the_post();
        the_title();
    endwhile;

    wp_reset_query

    In WP wp_reset_query() restores the $wp_query and global post data to the original main query. This function nether accept any parameter and nor it returns any values.

    NEXT and PREVIOUS POST LINK

    next posts link() function used to prints the link to the next set of posts within the current query. previous_posts_link() is used to points to newer entries that is toward the beginning of the post .

    Syntax-

    next_posts_link( 'NEXT PAGE >>' , $max_pages );

    $max_pages is used for number of pages . default is 0

    the author posts link

    Displays a link to all posts by an author and it does not takes any arguments also this tag must be used within The Loop.

    Syntax-

    the post thumbnail

    the_post_thumbnail() function is used to display the Featured Image of a post .

    Syntax-

    the_post_thumbnail( $size, $attr ); 

    Here size is the size of image that you want,
    attr is array of attribute/value pairs.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: