您好我有一个简单的网站,在列表中显示每个帖子标题,我正在尝试将活动帖子标题更改为在查看时不同。我试过了,但它没有用。
<ul class="students">
<?php
$IDOutsideLoop = $post->ID;
global $post;
$myposts = wp_get_archives('type=alpha');
foreach($myposts as $post) :
?>
<li <?php if(is_single() && $IDOutsideLoop == $post->ID) print 'style="font-weight:bold";'
?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
答案 0 :(得分:0)
使用get_posts而不是wp_get_archives
<?php
global $post;
$IDOutsideLoop = $post->ID;
$args = array( 'posts_per_page' => 999, 'orderby'=> 'title', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach($myposts as $post) :
?>
<li <?php if(is_single() && $IDOutsideLoop == $post->ID) print 'class="viewing"'; ?>>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>