WordPress.org

Ready to get started?Download WordPress

Forums

Problem with multiple loops on single.php – advice needed (3 posts)

  1. mattkevan
    Member
    Posted 7 years ago #

    Hi, I'm having a bit of problem with putting multiple loops on the single.php page.

    Basically, I want two additional loops showing specific posts from specific categories as well as the full text of a post. For some reason the loops are conflicting with one another – instead of showing the post text, it shows the content of one of the other loops.

    The code I'm using for the additional loops is:

    <?php $posts = get_posts( "category=10&numberposts=1" ); ?>
    <?php if( $posts ) : ?><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <?php the_content('Read more &raquo;'); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    (the only difference between the two additional loops is the category number and number of posts)

    The code to display the full single post is :

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
    <h2><?php the_title(); ?></h2>
    <div class="contenttext">
    <?php the_content('<p>Read more &raquo;</p>'); ?>
    </div>
    <?php link_pages('<p><strong>Pages:<strong> ', '</p>', 'number'); ?>
    <p class="postinfo"><strong>Posted:</strong> <?php the_time('F jS, Y') ?> under <?php the_category(', ') ?>.<br />
    <a href="<?php comments_link(); ?>"><strong>Comments:</strong> <?php comments_number('none','1','%'); ?></a>
    <?php edit_post_link('Edit this post',' | ',''); ?></p>
    <?php comments_template(); ?>
    <?php endwhile; else: ?>
    <p>No matching entries found.</p>
    <?php endif; ?>
    </div>

    You can see them in action here.

    I fear my knowledge of PHP and/or WordPress isn't enough to figure this one out by myself, so if anyone has any ideas I'd be most grateful. Thanks!

  2. Ryan Hellyer
    Member
    Posted 6 years ago #

    I had the same problem and solved it using the method recommended here ... http://www.webtalkforums.com/showthread.php?p=59973

  3. asony999
    Member
    Posted 6 years ago #

    Hello,

    I have same problem. My problem isn't solved by reading the above blog.

    is there any solutions ?

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic