面包屑痕迹显示不正确的痕迹?

时间:2013-09-01 20:04:03

标签: php wordpress wordpress-plugin

为什么以下代码会导致我的痕迹痕迹在面包屑中显示相同的帖子链接,无论您在网站上的哪个页面?

我多年来一直坚持这个问题而且无法理解......

明白我的意思here

<!-- Loops through Stories and returns images -->

    <ul style="width: 1520px">                                    
    <?php
        global $post;
            $category_id = get_cat_ID('stories');
            $args = array( 'numberposts' => 9, 'offset'=> 0, 'category'=> $category_id );
            $myposts = get_posts( $args );
        foreach( $myposts as $post ) : setup_postdata($post); ?>
            <!-- stories -->   
            <li>
                <figure>
                      <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>    
                    <a href="<?php the_permalink(); ?>">
                    <?php the_post_thumbnail(array(64,64)); // Declare pixel size you need inside the array ?></a>
                <?php endif; ?>
                </figure>
                <!-- /post thumbnail -->
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
          </li>
<?php endforeach; ?>
         </ul> 
<!-- /Loops through Stories and returns images -->

1 个答案:

答案 0 :(得分:0)

尝试重置postdata,例如this example from the Codex

<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
  setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; 
wp_reset_postdata(); ?>
</ul>