• Resolved satsuki03

    (@satsuki03)


    Hello, I’ve been testing this code on my locally installed 3.5 wordpress and it works well.

    <?php
       $recentposts = get_posts('numberposts=1&category=5');
       foreach ($recentposts as $post) :
           setup_postdata($post); ?>
           	<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    			<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    
    			<div class="content">
    				<?php the_excerpt(); ?>
    			</div>
    <?php endforeach; ?>
    		</div>

    However, after I have uploaded my theme into my 3.5.1 website, I used the same code TWICE with different values for Category (of course) on the same page, but the other code does not work. Which means the code worked only once.

    I’m not sure what should have been the problem because it worked on my locally installed one. Help?:)

Viewing 8 replies - 1 through 8 (of 8 total)
  • please post the full code with the two loops;

    make sure to end each loop with wp_reset_postdata();

    ‘but the other code does not work.’ – how exactly does it not work?

    Thread Starter satsuki03

    (@satsuki03)

    Hello, the whole code is like this.

    <div id="mid-container">
    <div id="latestn">
    <?php
       $recentposts = get_posts('numberposts=3&category=5');
       foreach ($recentposts as $post) :
           setup_postdata($post); ?>
           	<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    			<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    
    			<div class="front">
    				<?php the_content(); ?>
    			</div>
    
    			<div class="postmetadata">
    				<?php the_tags('Tags: ', ', ', '<br />'); ?>
    				Posted in <?php the_category(', ') ?> |
    				<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    			</div>
    <?php endforeach; ?>
    </div>
    
    <div id="latestb">
    <?php
       $recentposts = get_posts('numberposts=3&category=7');
       foreach ($recentposts as $post) :
           setup_postdata($post); ?>
           	<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    			<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    
    			<div class="front">
    				<?php the_content(); ?>
    			</div>
    
    			<div class="postmetadata">
    				<?php the_tags('Tags: ', ', ', '<br />'); ?>
    				Posted in <?php the_category(', ') ?> |
    				<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    			</div>
    <?php endforeach; ?>
    		</div>
    </div>

    By not working;
    After uploading it to the website, there should be two loops (two boxes containing different posts from different categories); it does not work in a way that there’s only one box that appears, when locally it works (both appears).

    make sure that the used category ids do exist with posts in that site.

    do the surrounding html tags appear in the browser?
    like: <div id="latestb">

    Thread Starter satsuki03

    (@satsuki03)

    Using firebug to view it, yes the html tags do appear, I’ve also made sure that the category ids do exist, which is why I’m not really sure why the other part does not appear. 🙁

    this is marked as ‘resolved’ – how did you do it?

    Thread Starter satsuki03

    (@satsuki03)

    I did not mark it as resolved, I haven’t done it.

    what template is your code inserted in?
    what theme are you using?

    general troubleshooting:

    – deactivate all plugins to see if that solves the problem;
    if it does, reactivate one plugin at a time and check to find the interfering plugin.

    – try to switch themes to the default theme Twenty Twelve, and add the code there into a comparable template.

    try to re-write the second ‘get_posts’ code to use a different syntax:

    $recentposts = get_posts( array( 'posts_per_page' => 3, 'cat' => 7) );

    or use the category slug in the ‘get_posts’ code:

    $recentposts = get_posts( array( 'posts_per_page' => 3, 'category_name' => 'what-ever-slug') );
    Thread Starter satsuki03

    (@satsuki03)

    I tried to switch themes and put it into twentytwelve. I re-checked all the codes again and changing the syntaxes made it work. (also made sure that the categories are correctly numbered as well.)

    Thank you very much for your help! 🙂

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

The topic ‘Multiple Loops not working in 3.5.1?’ is closed to new replies.