• hey,

    i have related posts widget on my website that appear at the bottom of an article, but in the description of every post i have the description of the current post (in single.php)

    how can i resolve this?

    my code:

    <?php $posts = get_posts('orderby=rand&numberposts=3'); foreach($posts as $post) { ?>
    
                <div class="article">
                    <?php the_post_thumbnail(); ?>
                    <a href="<?php the_permalink(); ?>"><span style="font-weight: bold;height: 32px;padding: 5px;float: right;"><?php the_title(); ?></span></a>
                    <span style="padding: 5px;height: 62px;overflow:hidden;float: right;"><?php the_excerpt(); ?></span>
                    <div class="details">
                        <span style="width: 110px;float: left;"><img align="absmiddle" style="float: right;margin-left: 5px;" src="<?php echo get_template_directory_uri(); ?>/img/tinyicon1.png"/><?php the_category(' '); ?></span>
                        <span style="float: right;"><img align="absmiddle" style="float: right;margin-left: 5px;" src="<?php echo get_template_directory_uri(); ?>/img/tinyicon2.png"/><?php comments_popup_link( '<span class="leave-reply">' . __( '0 תגובות', 'twentyeleven' ) . '</span>', __( 'תגובה 1', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?></span>
                    </div>
                    <div class="tinydate"><?php the_time('d/m/y G:i') ?><?php edit_post_link( __( '<img src="http://www.sbdrecipes.com/images/editIcon.gif" width="13" height="13" alt="" />', 'twentyeleven' ), '' ); ?></div>
                </div>
    
    <?php } ?>

    i think the description is this :
    <?php the_excerpt(); ?>

    demo: (in hebrew, forgive me)
    http://weird.co.il/2013/09/08/7-%D7%A1%D7%99%D7%91%D7%95%D7%AA-%D7%9C%D7%9E%D7%94-%D7%91%D7%A8%D7%95%D7%A1-%D7%9C%D7%99-%D7%94%D7%99%D7%94-%D7%94%D7%92%D7%93%D7%95%D7%9C-%D7%9E%D7%9B%D7%95%D7%9C%D7%9D/

Viewing 4 replies - 1 through 4 (of 4 total)
  • review
    http://codex.wordpress.org/Template_Tags/get_posts

    particular the example codes;
    i.e. make sure to include this:

    setup_postdata( $post );

    Thread Starter yortem

    (@yortem)

    im not really a programmer but i think you didnt understand me.
    the random post gives me the right title and image but the description isnt right. its giving me the description of the current article, not the random article.

    i will glad if you give me more details how can i fix it.

    (also, english isnt my nativ language, so forgive me.)

    have you tried to add setup_postdata( $post ); into your code?

    like in this line:

    <?php $posts = get_posts('orderby=rand&numberposts=3'); foreach($posts as $post) { setup_postdata( $post ); ?>
    Thread Starter yortem

    (@yortem)

    thank you very much!! its worked!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Releted post problem’ is closed to new replies.