最新问题调用代码:
<?php $rand_posts = get_posts(‘numberposts=10&orderby=date’);foreach($rand_posts as $post) : ?>
<li><a href=”<?php the_permalink(); ?>”> <?php echo mb_strimwidth(get_the_title(), 0, 32, ”); ?></a></li>
<?php endforeach;?>
相关文章调用代码(通过分类来判断相关文章):
<ul>
<?php
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$args = array(
‘category__in’ => array( $cats[0] ),
‘post__not_in’ => array( $post->ID ),
‘showposts’ => 6,
‘caller_get_posts’ => 1
);
query_posts($args);
if (have_posts()) :
while (have_posts()) : the_post(); update_post_caches($posts); ?>
<li>* <a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
<?php endwhile; else : ?>
<li>* 暂无相关文章</li>
<?php endif; wp_reset_query(); } ?>
</ul>
文章下一篇上一篇调用:
<?php previous_post_link(‘上一篇: %link’); ?>
<?php next_post_link(‘下一篇: %link’); ?>
扩展:上一篇下一篇另一种写法:
<?php if (get_previous_post()) { previous_post_link(‘%link’);} else {echo “没有了,已经是最后文章”;} ?>
<?php if (get_next_post()) { next_post_link(‘%link’);} else {echo “没有了,已经是最新文章”;} ?>