Forums

Page 2 of blog is exactly the same as first (5 posts)

  1. robcub
    Member
    Posted 2 years ago #

    Hi, The site has a static front page but the blog posts go in here.

    http://www.fcdynamos.com/home

    Here is my index.php
    http://wordpress.pastebin.ca/1842972

    There are three loops as I wanted the newest post to be featured large, the next four with a thumbnail and the rest (5) to be just listed. It works fine except when it comes to the second page - http://www.fcdynamos.com/home/page/2 - which, as the title of this thread suggests, is exactly the same as the first page.

    I'm sure it must be something to do with the three loops but I'm really no expert in PHP. And, if I can get it to work, I would like page 2, 3, and 4 to be just 10 posts with excerpts not like how it is on the first page.

    If anyone has any idea on what I can do I would be extremely grateful.

  2. westondeboer
    Member
    Posted 2 years ago #

    I don't know, but try this

    $the_newest = get_posts($query_string . "numberposts=1");
    $the_newer = get_posts($query_string . "numberposts=4&offset=1");
     $the_new = get_posts($query_string . "numberposts=5&offset=5&order=DESC&orderby=post_date");

    I would look into doing your code like this, so it only has to do a db query once and show it depending.

    <?php get_header(); ?>
    
    <?php include(TEMPLATEPATH."/l_sidebar.php");?>
    
    <div id="container">
    
    <?php global $query_string; ?>
    
    <?php $k=0; ?>
    
    <?php query_posts($query_string . "&numberposts=5&offset=5&order=DESC&orderby=post_date"); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <?php // if first post show it like this ?>
    <?php if ($k == 0) { ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="/wp-content/uploads/<?php echo get_post_meta($post->ID, 'main-image', true); ?>" class="link-img" /></a>
    
    <h2 id="main-post"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    <div id="main-entry">
    
    <?php the_excerpt(__('Read more...')); ?>
    
    <span class="read_more"><a title="Read more about: <?php the_title(); ?>" href="<?php the_permalink() ?>">Read more...</a></span>
    
    </div>
    
    </div>
    
    <?php // if not first post show it like this
    <?php } else { ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="/wp-content/uploads/<?php echo get_post_meta($post->ID, 'main-image', true); ?>" class="link-img" /></a>
    
    <h2 id="main-post"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    <div id="main-entry">
    
    <?php the_excerpt(__('Read more...')); ?>
    
    <span class="read_more"><a title="Read more about: <?php the_title(); ?>" href="<?php the_permalink() ?>">Read more...</a></span>
    
    </div>
    
    </div>
    
    <?php } ?>
    
    <?php $k++; ?>
    
    <?php endwhile; ?>
  3. robcub
    Member
    Posted 2 years ago #

    Hi poil11, thank you for taking the time to offer solutions. As I've said, I don't really get PHP yet so I apologise in advance for anything stupid I'm about to say...

    I tried the first option and all I got was no posts at all just "next page".

    I tried the second option and completely pasted in your re-written index.php. Firstly I got an unexpected < on line 33 so I deleted that line completely - "<?php // if not first post show it like this" and I got the oldest 7 posts and then no right sidebar and no footer.

    I need to do some learning at php.net and w3c schools.
    Is there a resource that can tell you - "if it's the first post do this; if it's the second post do this; if it;s the second page do this" etc.?

  4. westondeboer
    Member
    Posted 2 years ago #

    ya basically

    <?php if ($k == 0) { ?> is the first post and then

    <?php if ($k == 1) { ?> is the second post and then

    <?php if ($k == 2) { ?> is the third post on and on

    I don't have time to completely rewrite your code, i didn't include everything. Just a starting point.

  5. robcub
    Member
    Posted 2 years ago #

    Yes, I see that now. Thank you. I think I will hack out a solution now (I'll put a direct link to page 2 of the category at the bottom of the index page as there's only one category) and I'll have another look at PHP later - and I'll try to do learn PHP properly from the bottom up rather than pasting things in from all over the place and then wondering why it doesn't work.

    Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic