• Hi, I searched the forums and the Codex but I could find how to do what I want to do, although I think it is not very complicated but I’m not good with code…

    So here is my problem: I have my homepage on index.php. I use the main loop to display the latest post with content and the following ones with excerpt only.

    <?php $i=1; ?>
    <?php while(have_posts()) : the_post(); ?>
    <?php if ($i == 1) : ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
    <?php the_content(); ?>
    
    <br />
    <br />
    
    <?php else : ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
    <?php the_excerpt(); ?>
    
    <?php endif; ?>
    <?php $i++; ?>
    <?php endwhile; ?>

    I works fine but what I want is only show the latest post with content on the homepage, not on the following pages (I use PageNavi Plugin). I tried to place is_home function before and after the main Loop, but nothing works, I got plenty of syntax errors I don’t know why…

    So for now, when I go on page 2 (/page/2/), the first post on the page displays the content and the following ones the excerpt, exactly like on my homepage. And that’s what I want to avoid.

    Any idea? Thanks a lot for your help! πŸ™‚

Viewing 14 replies - 1 through 14 (of 14 total)
  • Try modifying your code like this:

    <?php
    $paged = get_query_var('paged');
    $paged = ($paged) ? $paged : 1;
    $i=1; ?>
    <?php while(have_posts()) : the_post(); ?>
       <?php if ($i == 1 || $paged > 1) : ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
          <?php the_content(); ?>
    Thread Starter Alkorr

    (@alkorr)

    Hi vtxyzzy, thanks for your help but it doesn’t work, it didn’t change anything… The /page/2/ shows first post on page with the_content like on the homepage πŸ™

    But I understand what you intended to do and it sounded great. Any other idea? πŸ˜‰

    I would do a little debugging by printing out some info to see if $paged is getting set the way I think it should:

    <?php
    $paged = get_query_var('paged');
    $paged = ($paged) ? $paged : 1;
    echo "<p><h2>Paged:$paged</h2></p>";
    $i=1; ?>
    <?php while(have_posts()) : the_post(); ?>
       <?php if ($i == 1 || $paged > 1) : ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
          <?php the_content(); ?>

    See if $paged changes to the correct page number.

    Thread Starter Alkorr

    (@alkorr)

    Ok, I tried that it shows the right page: Paged:1 on homepage and Paged:2 when I’m on /page/2/

    So now I wonder why I can’t make your code work?!

    That is a puzzler. Check your if-test carefully – maybe a misspelled variable. If not that, you might try putting in some parens to force grouping in the if-test, but I don’t see why they should be necessary.

    <?php if (($i == 1) || ($paged > 1)) : ?>

    Thread Starter Alkorr

    (@alkorr)

    It doesn’t change anything… I’m cursed!

    Thank you very much for your help vtxyzzy! πŸ™‚

    OK – try to force all the posts to full content like this:

    <?php if (true || ($i == 1) || ($paged > 1)) : ?>

    If that doesn’t work, then we need to look somewhere other than the if-test for the answer.

    Thread Starter Alkorr

    (@alkorr)

    Hi vtxyzzy! I just tried it and indeed, all posts show now full content on all the pages. So the problem may come from the code, but from where?

    Thanks for you help!

    Since that worked, the problem is in the if-test, not in other code. I still suspect a misspelled variable name. Please copy and paste a few lines around the one containing the if-test so I can take a look.

    Thread Starter Alkorr

    (@alkorr)

    Sure, here is the code on my index.php:

    <?php get_header(); ?>
    
    <?php
    $paged = get_query_var('paged');
    $paged = ($paged) ? $paged : 1;
    echo "<p><h2>Paged:$paged</h2></p>";
    $i=1; ?>
    
    <?php while(have_posts()) : the_post(); ?>
    <?php if (true || ($i == 1) || ($paged > 1)) : ?>
    
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
    <?php the_content(); ?>
    
    <br />
    <br />
    
    <?php else : ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br />
    <?php the_excerpt(); ?>
    
    <?php endif; ?>
    <?php $i++; ?>
    <?php endwhile; ?>
    
    <br />
    <br />
    
    <center><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></center>
    
    <?php get_sidebar(); ?>

    I hope it will help!

    Well, it didn’t help!

    Since the code shows the full content when the ‘true’ is present, it should work when the if-test is true.

    Since the display of $paged is showing that $paged is being set greater than 1, that part of the test should be true on pages other than the first.

    Very puzzling, and I am out of ideas! Sorry!

    Thread Starter Alkorr

    (@alkorr)

    This is weird… So when you paste the code I copied just above, it works fine with you? This is very puzzling indeed!!

    Anyway, thank you very much for your help vtxyzzy, I hope I will finally find out what’s wrong… πŸ˜‰

    I could not actually test the code you pasted. I was just reviewing the results you gave from earlier tests.

    Alright, I did test the code and it works. Really strange! Maybe some other code is using a variable named $paged. Try changing the name to $my_page_num.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Specific display on Homepage’ is closed to new replies.