• I may be going about this totally backward but I’m trying to create some logic that is basically this:

    if # of posts in a category is < # of posts per page(set in wordpress settings)
    then
    do not display the elements [here]
    else
    the code as normal
    end if

    does anyone know what i could use to query the number of posts in a category w/o inputting a specific category id? also, what do i use to reference the current setting of posts per page?

    TIA

Viewing 3 replies - 1 through 3 (of 3 total)
  • if you don’t use a custom query, the this should give the actual number of posts to show:
    $num_of_posts = $wp_query->post_count;

    and this might get the ‘posts-per-page’:
    $max_num_post = get_option('posts_per_page');

    Thread Starter centaurreader

    (@centaurreader)

    so would
    $num_of_posts = $wp_query->post_count;
    give me the number of posts in total for the blog or is there a way to specify a particular category?

    thanks for your quick response on this.

    $num_of_posts = $wp_query->post_count;

    will give you the number of post in the current query. However, as alchymyth said, you will have to use a custom query.
    Which could look like this:

    <?php
    query_posts('posts_per_page=-1');
    
    $num_of_posts = $wp_query->post_count;
    $max_num_post = get_option('posts_per_page');
    
    if($num_of_posts > $max_num_post): ?>
    
    Your loop for more posts than the max number of post per page here.
    
    <?php else : ?>
    
    Your normal loop here.
    
    <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Posts per page query’ is closed to new replies.