0

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

我已经被这个问题困扰了很久,只是无法弄清楚......

看看我在这里的意思。

<!-- 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 -->
4

1 回答 1

0

尝试重置 postdata,例如 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>
于 2013-09-01T20:26:19.040 回答