wordpress怎么添加相关文章
< php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
$tagIDs = array();
if ($tags) {
echo ‘或许你会感兴趣的文章
’;
echo ‘’;
’;
$tagcount = count($tags);
for ($i = 0; $i < $tagcount; $i++) {
$tagIDs[$i] = $tags[$i]->term_id;
}
$args=array(
‘tag__in’ => $tagIDs,
‘post__not_in’ => array($post->ID),
‘showposts’=>8, // 显示相关日志篇数
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); >
- < php the_time(__(‘Y-m-d’)) >” rel=”bookmark” title=”< php the_title(); >”>< php the_title(); >
< php endwhile;
echo ‘
} else { >
< php
query_posts(array(‘orderby’ => ‘rand’, ‘showposts’ => 8)); //显示随机日志篇数
if (have_posts()) :
while (have_posts()) : the_post(); >
- < php the_time(__(‘Y-m-d’)) >” rel=”bookmark” title=”Permanent Link to < php the_title(); >”>< php the_title(); >
< php endwhile;endif; >
< php }
}
$post = $backup;
wp_reset_query();
>