我正在试图找出当前查看的帖子的索引(单个帖子页面)。
我在侧边栏中概述了同一类别的文章。但是,当用户导航到位于第2页的帖子时,文章现在应该显示第2页的文章,即使是在单个帖子页面中。
这是边栏显示实际页面帖子的代码:
<ul>
<?php
$offset = 0;
//THIS IS THE PROBLEMATIC PART
if (is_single()) {
$modulo = $wp_query->current_post % 6; // $wp_query->current_post somehow ever returns 0
$offset = $wp_query->current_post - $modulo;
}
if (is_tag()) {
$args = array(
\'posts_per_page\' => 6,
\'tag\' => get_query_var(\'tag\') );
}
else {
$args = array(
\'posts_per_page\' => 6,
\'category\' => $cat_id,
\'offset\' => $offset );
}
$myposts = get_posts( $args );
$i = 0;
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<?php if (is_blog()) { ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php } else { ?>
<a href="#" onclick="goTo(<?php echo $i; ?>);return false;"><?php the_title(); ?></a>
<?php } ?>
</li>
<?php $i++; endforeach; ?>
</ul>
与注释一样,$wp\\u query->current\\u post总是返回0,我认为这是因为它在循环之外。我如何解决这个问题?