WordPress.org

Ready to get started?Download WordPress

Forums

Change post count for index/home page and the following pages in WP_Query loop (9 posts)

  1. brandon.matson
    Member
    Posted 1 year ago #

    I am curious how I can throttle the number of posts to display between the home/index page and the following sequential pages generated by the WP_Query loop.

    This is the code I am currently using to set the loop and post count:

    <?php
     $my_query = new WP_Query('showposts=4'.'&paged='. $paged);
     while ($my_query->have_posts()) : $my_query->the_post();
     $do_not_duplicate[$post->ID] = $post->ID; ?>

    But I cant figure out how to change the post count once I am off of the home page. I have tried different variations of if/else is_front_page() but I have had no luck. Any help is appreciated.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Please explain more what you want to do, with an example. If you want to show fewer posts on the first page than on following pages, this article might help:

    http://wordpress.mcdspot.com/2010/04/01/short-first-page/

    I have not worked out how to have a longer first page.

  3. brandon.matson
    Member
    Posted 1 year ago #

    Thanks thats in line with what I was looking for. Basically on this particular site I need 4 home page posts followed by 10 posts on the following pages.

  4. brandon.matson
    Member
    Posted 1 year ago #

    VTX- I tried using that code from the link you provided and I got an error, "Parse error: syntax error, unexpected $end". I checked the entire file for validation errors, missing brackets, short form tags etc but I cant find anything, the only variable is the code string you supplied any thoughts?

  5. vtxyzzy
    Member
    Posted 1 year ago #

    Put your modified file into a pastebin and post a link to it here so I can take a look.

  6. brandon.matson
    Member
    Posted 1 year ago #

    Here is the link, let me know if that didnt work.

    http://pastebin.com/YSAMiPSu

    Thanks again for your help.

  7. vtxyzzy
    Member
    Posted 1 year ago #

    You are missing an endif - the second one shown below:

    .                  </div><!-- #nav-below -->
                   <?php endif; ?>
    
                </div>
             <?php endif; ?>
          </div>
    
          </div>
    
          <div id="sidebar">
             <?php get_sidebar(); ?>
          </div>
  8. brandon.matson
    Member
    Posted 1 year ago #

    Ok that i think was the endif that was on line 54, I just needed to move it down.

    That seems to do it, thanks for your help.

  9. vtxyzzy
    Member
    Posted 1 year ago #

    Are you sure? I think the one on line 52 matched the if on line 46: if ( is_active_sidebar(...

Topic Closed

This topic has been closed to new replies.

About this Topic