• Hi there, I got a bit of an issue with all my posts displaying the same content after adding a small loop to the sidebar.
    Here’s my single.php code:
    <?php
    // Exit if accessed directly
    if ( !defined('ABSPATH')) exit;

    get_header(); ?>
    <div class="container">
    <!-- SIDEBAR LEFT -->
    <div class="red left">Latest

    <?php $posts = get_posts('numberposts=3&offset=0');
    foreach ($posts as $post) : start_wp(); ?>

    <div style="width:190px; height: 170px;margin-bottom:7px;"><div>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( '190x110' ); } ?><div><div><span class="title"><b>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="bookmark" ><?php the_title(); ?></b></span></div></div></div>

    </div><?php endforeach; ?>

    </div></div>

    <!-- SIDEBAR LEFT END -->

    <div class="blue2">

    <div class="box"><p class="tit" style="margin-left:0px;margin-top:0px;margin-bottom:10px;"><?php the_title(); ?></p>

    <?php the_content(); ?></div></div></div>

    <?php get_footer(); ?>

    What do I do wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Kris

    (@omgb)

    exporting it to sidebar.php doesnt change anything either.

    moving the ‘latest posts’ sidebar below <?php the_content(); ?> gets rid of the issue. if worse comes to worst i guess i could position it from there, but there must be easier solution…

    thanks in advance

    Thread Starter Kris

    (@omgb)

    oh just noticed my sidebar didnt paste properly

    <!-- SIDEBAR LEFT -->
        <div class="red left">Latest<br/><br/>
    
    <?php $posts = get_posts('numberposts=3&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    
          <div style="width:190px; height: 170px;margin-bottom:7px;"><div><a href="<?php the_permalink() ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( '190x110' ); } ?></a><div><div><span class="title"><b><a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="bookmark" ><?php the_title(); ?></a></b></span></div></div></div>
    
    </div><?php endforeach; ?>  
    
        </div></div>      
    
    <!-- SIDEBAR LEFT END -->

    after the endforeach; make sure to end your sidebar code with:

    wp_reset_postdata();

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Same content for different posts in single.php’ is closed to new replies.