WordPress.org

Ready to get started?Download WordPress

Forums

Related Posts - Ignore for First Post Only? (3 posts)

  1. shiola
    Member
    Posted 5 years ago #

    I've got this plugin - http://fairyfish.net/2007/09/12/wordpress-23-related-posts-plugin/ - and would like to NOT have the related post function work for the first (most recent) post but have it work for all others?

    Is this possible?

    The code on my index.php calling this plugin is:

    <div>
    <h6>Related Items »</h6>
    <?php wp_related_posts(); ?>
    </div>

    Cheers.

  2. MichaelH
    Member
    Posted 5 years ago #

    Something along the line of this?

    <?php
    $count = 0;
    if (have_posts()) {
     while (have_posts()) : the_post();
      $count++;
        if ($count <= 1) {
          the_content();
        } else {
          the_content();
          wp_related_posts();
        }
     endwhile;
    }
    ?>
  3. shiola
    Member
    Posted 5 years ago #

    Thanks for the reply.

    Yeah, you got the related posts off the first post but it seems to be repeating every post on the homepage about 3 or 4 times, plus the related posts for the other posts are slightly messed up. I had a play with your code but it's not fixed.

    <?php
    $count = 0;
    if (have_posts()) {
     while (have_posts()) : the_post();
      $count++;
        if ($count <= 1) {
          the_content();
        } else {
          echo '<div style="margin: 40px 0 0 0;"><h6>Related Items »</h6>';
          the_content();
          wp_related_posts();
          echo '</div>';
        }
     endwhile;
    }
    ?>

    This isn't vital but if you have any simple ideas then let me know.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic