WordPress.org

Ready to get started?Download WordPress

Forums

post per page (4 posts)

  1. saravanan
    Member
    Posted 1 year ago #

    hi,

    how to check post count per page?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Here are some post count variables you can use in your theme template files:

    // count for total found posts on the current (query) page.
    $current_page_post_count = $wp_query->post_count;
    echo 'there are ' . $current_page_post_count . ' posts on this page';
    
    // count for total found posts for the current query
    $current_query_total_post_count = $wp_query->found_posts;
    echo 'there are ' . $current_query_total_post_count . ' posts in total for this query';
    
    // current post number inside the loop
    // (starts with 0)
    $current_post_in_loop = $wp_query->current_post;
    echo 'this is post number' . $wp_query->current_post; 
    
    // count of all posts published, regardless of current query
    $count_posts = wp_count_posts();
    echo 'total posts = ' . $count_posts->publish;
    
    // max post setting on wp-admin > Settings > Reading
    $default_posts_per_page = get_option('posts_per_page');
    echo 'default posts_per_page = '. $default_posts_per_page;
  3. saravanan
    Member
    Posted 1 year ago #

    thanks..

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    No problem.

Topic Closed

This topic has been closed to new replies.

About this Topic