• Hi!

    I’m creating a theme an I would display on the last post in the home page, now I’ve this code:

    <?php
    if (is_home() && !is_paged())
        query_posts('posts_per_page=1');
    ?>

    it works, it displays the latest post on the home, but when I click to Old Articles i get Not Found (url https://blog.domain/wordpress/?paged=2

    and I don’t know how to resolve ??

    also when I go to https://blog.domain/wordpress/?paged=1
    I get the post but is also displayed the latest post.

    Thanks for any reply

Viewing 11 replies - 1 through 11 (of 11 total)
  • Try query_posts('showposts=1');

    Thread Starter patrick91

    (@patrick91)

    no, it’s the same ??

    Is this an archive (posts) page or within a page template? Only is_home() and is_front_page() return slightly different results depending upon what type of page you’re on. Also:

    – where are you adding the query_posts line in relation to the Loop?
    – what are you using to generate the previous posts link? posts_nav_link()?

    https://codex.www.ads-software.com/Template_Tags/query_posts#Example_3

    Thread Starter patrick91

    (@patrick91)

    thanks for the reply.
    I’m in index.php and I want to show the latest post if is the home page, so I change the post_per_page var to 1 if I’m in the home and it is not a page, but if I do so the navigation is broken because I get the next page link euqual to url?paged=2 which is correct if I’ve post_per_page equal to 1 everytime, but post_per_page is

    1. equals to 1 for the first page
    2. equals to 5 for other pages

    for nav links I use this code:

    <div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries')) ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;')) ?></div>
    		</div>

    What about trying:

    <?php
    if (is_home()) {
    	if(!is_paged()) $ppp=1;
    	else $ppp=5;
    }
    else $ppp = 5; // assuming this template is also used for categories, tags etc
    query_posts('posts_per_page='.$ppp);
    ?>
    Thread Starter patrick91

    (@patrick91)

    mhm, it seems workin’ but when I go to the second page I get also the latest post ??
    we need to set a start parameter?

    The offset parameter, I think:

    <?php
    if (is_home()) {
    	if(!is_paged()) {
    		$ppp=1;
    		$offset = 0;
    	}
    	else {
    		$ppp=5;
    		$offset = 1;
    	}
    }
    else {
    	$ppp = 5; // assuming this template is also used for categories, tags etc
    	$offset = 0;
    }
    query_posts('posts_per_page='.$ppp.'&offset='.$offset);
    ?>
    Thread Starter patrick91

    (@patrick91)

    ohhh, it’s workin’ ??

    Thank you very much ??

    Thread Starter patrick91

    (@patrick91)

    It doesn’t work if you have pretty url ?? like blog.url.tld/page/2

    works only with url like this blog.url.tld/?paged=2

    why this?

    Shouldn’t make any difference…

    Do pretty permalinks work for everything else?…

    It’s more likely the permalinks are not working correctly.

    Thread Starter patrick91

    (@patrick91)

    they’re working fine ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Display the latest post in the home’ is closed to new replies.