怎么实现“相关文章”功能
有实例最好了
有实例最好了
解决方案 »
- jquery调用wcf的json反序列化问题
- 未能加载文件或程序集“Microsoft.Web.UI.WebControls, Version=1.0.2.226
- asp.net 里的Gridview如何在标题头列添加按钮
- textbox 验证控件,为什么是点击按钮才触发验证控件?而不是离开textbox时触发的?
- IIS配置
- 传到网上后验证控件失效
- 在一个***.aspx.vb页面里,就写一次数据库连接字符串。然后怎么调用?
- 如何从反射获得命名空间下所有的程序?
- 输入的内容如果和下拉框中的某项相同时,会自动选中下拉框中那一条
- 跳出 WIN对话框 问题。为什么我点取消代码还是往下执行。
- 提问,求解答gridview绑定问题
- VS2010 GridView调用JS
01
<ul id="tags_related">
02
<?php
03
$post_tags = wp_get_post_tags($post->ID);
04
if ($post_tags) {
05
foreach ($post_tags as $tag)
06
{
07
// 获取标签列表
08
$tag_list[] .= $tag->term_id;
09
}
10
// 随机获取标签列表中的一个标签
11
$post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];
12
// 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表
13
$args = array(
14
'tag__in' => array($post_tag),
15
'category__not_in' => array(NULL),
// 不包括的分类ID
16
'post__not_in' => array($post->ID),
17
'showposts' => 10,
// 显示相关文章数量
18
'caller_get_posts' => 1
19
);
20
query_posts($args);
21
if (have_posts()) :
22
while (have_posts()) : the_post(); update_post_caches($posts); ?>
23
<li><a href="<?php the_permalink(); ?>" rel="book" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
24
<?php endwhile; else : ?>
25
<!-- 没有相关文章的话随机抽取文章 -->
26
<?php $rand_posts = get_posts('numberposts=10&orderby=rand'); foreach( $rand_posts as $post ) : ?>
27
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
28
<?php endforeach; ?>
29
<?php endif; wp_reset_query(); } ?>
30
</ul>