我正在上使用以下循环index.php
.
当前查看的页面将是循环中的链接之一
How to make sure it is marked as current?
<ul id="questions" class="subpage">
<?php
$index_query = new WP_Query( array( \'post_type\' => \'faq\', \'orderby\' => \'modified\', \'posts_per_page\' => \'-1\', \'order\' => \'DESC\' ) );
while ( $index_query->have_posts() ) : $index_query->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php echo get_field(\'short_version\'); ?> »</a></li>
<?php endwhile; ?>
</ul>
get_field()
是来自的函数
Advanced Custom Fields 并具有以下格式:
get_field($field_name, $post_id);
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
这是您的代码的重写版本
<ul id="questions" class="subpage">
<?php
$current_id = get_the_ID();
$index_query = new WP_Query( array( \'post_type\' => \'faq\', \'orderby\' => \'modified\', \'posts_per_page\' => \'-1\', \'order\' => \'DESC\' ) );
while ( $index_query->have_posts() ) : $index_query->the_post();
if(get_the_ID() == $current_id)
echo \'this post has the same ID as the current global one\';
?>
<li><a href="<?php the_permalink(); ?>"><?php echo get_field(\'short_version\'); ?> »</a></li>
<?php endwhile; ?>
</ul>
请注意,在索引上。php您可以查询单个帖子类型以及归档文件(取决于主题)。如果是存档,则仅与该存档的第一篇文章匹配。如果要匹配其他类型的模板,请参阅
conditional tags