WordPress.org

Ready to get started?Download WordPress

Forums

Help on Slight Paging Problem (3 posts)

  1. srm2888
    Member
    Posted 3 years ago #

    Hi there, first post. I am having a slight problem with paging. I wanted the front page to have only one post, then when you paged with the "next" or "previous" to also only only show one post. However, if you went to a category link, or just a different page I wanted it to display the amount of pages specified in the Settings->Reading->amount per posts.

    I created a home.php to attempt to start doing this, it looks identical to MainIndex.php except for this added script

    <?php
    
    get_header();
    query_posts('posts_per_page=1'); //returns only the front page\
    
    ?>

    Now the problem is it keeps only giving the front page even thought the paging mechanisms.
    The actual paging code is

    <div id="paging">
    
    						<?php $previous = get_bloginfo('template_directory'); ?>
    
    						<div id="alignright"><?php next_posts_link('<img src="' . $previous . '/images/previous.png" alt="Previous" title="Previous" />') ?></div>
    						<div id="alignleft"><?php previous_posts_link('<img src="' . $previous . '/images/next.png" alt="Next" title="Next" />') ?></div>
    					</div>

    Hope the spacing is okay. While I have a decent amount of coding experience, I am rather new to the scripting/web-development game, and started wordpress yesterday. I don't understand why this code is repeated three times in hte page Page.php, MainIndex.php, and in home.php (well that's kind of my fault), the LOOP is also repeated three times. Im sure there is a sepcific reasonf for this as if they are actually three different places. Just seems rather redundant. Anyhow, anyone know a quick fix to this without adding a plug in?
    Thanks for the help!

  2. kkarpieszuk
    Member
    Posted 3 years ago #

    i'm sure that you didnt check documentation ;) its explained at ebginnning

    change your code to

    <?php
    
    get_header();
    global $query_string;
    query_posts($query_string . 'posts_per_page=1'); 
    
    ?>

    more:
    http://codex.wordpress.org/Function_Reference/query_posts

  3. srm2888
    Member
    Posted 3 years ago #

    Thanks, yes somehow I missed that tidbit there; I did check the documentation though.

    In case anyone else has this problem make sure
    you add the ampersand like this

    <?php
    
    get_header();
    global $query_string;
    query_posts($query_string . '&posts_per_page=1'); 
    
    ?>

    Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.