无插件实现WordPress相关文章调用方法
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

在前面蜗牛分享到\\”放弃使用WordPress Related Posts插件的理由\\”,本来还想用另外一款\\”Yet Another Related Posts Plugin\\”插件的,国外用户比较多,而且非常的热门,Matt Cutts也在博文中把这款相关文章插件作为推荐的首选。但是我在使用后发现其他都还不错,就是唯一不能自定义位置,他默认直接在文章底部显示,万一文章有模板底部添加内容,那内容就在调用下面。所以我还是放弃使用插件,直接采用无插件实现WordPress相关文章调用方法。
第一步,在需要添加相关内容调用的位置,编辑下面代码:
<div class=\\”post-relate\\”>
<h3>你可能喜欢如下内容:</h3>
<ul>
<php
$post_tags = wp_get_post_tags($post->ID);
if ($post_tags) {
foreach ($post_tags as $tag){
$tag_list[] .= $tag->term_id;
}
$post_tag = $tag_list[ mt_rand(0, count($tag_list) – 1) ];
$args = array(
\\’tag__in\\’ => array($post_tag),
\\’category__not_in\\’ => array(NULL),
\\’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 h=\\”<php the_permalink(); >\\” rel=\\”bookmark\\” title=\\”<php the_title_attribute(); >\\”><php the_title(); ></a>
</li>
<php endwhile; else : >
<php $ashu_cats = wp_get_post_categories($post->ID);
if( $ashu_cats ){
$args = array(
\\’category__in\\’ => array( $ashu_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 h=\\”<php the_permalink(); >\\” rel=\\”bookmark\\” title=\\”<php the_title_attribute(); >\\”><php the_title(); ></a>
</li>
<php endwhile; endif; wp_reset_query(); } >
<php endif; wp_reset_query(); } >
</ul>
<div class=\\”clear\\”></div>
</div>
第二步:样式添加
如果添加上述的代码后感觉界面还不错,就直接使用,如果不行,需要用到下面的样式。
.post-relate{padding:10px 5px;color:#888;}
.post-relate h3{margin:0;line-height:22px;Verdana;font-size:14px;}
.post-relate ul{margin:5px 15px;padding:0px 5px;}
.post-relate li{margin:0px 0px;padding:2px 0px 2px;}
样式还需要根据自己的需要调整。这样我们不用插件也能实现效果,降低WP的内存消耗。能不用插件尽量不使用。
[WordPress相关]历史优惠活动内容
猜你可能想看的VPS
- Laravel Passport 提示→Method attempt d全球[VPS测评]
- HostPapa→.com 域名 首年 0.99 美金 每账户限 5 个全球[VPS测评]
- 数脉科技→366 元 月 E3-1230v2 16GB 内存 1TB 或香港VPS[主机]
- PacificRack→$13.5 年 KVM-1GB 35GB 1TB全球[VPS测评]
- 腾讯云→国内云服务器年付 99 元起 单核 2G2M 三年仅 680 元全球[VPS测评]
- Linux 下端口被占用的解决办法全球[VPS测评]
- 标准互联→襄阳电信高防 VPS 100G 200G 防御 Hyper-V全球[VPS测评]
- Bootstrap 清除浮动全球[VPS测评]
- 疯狂猜成语 图猜成语一个袋子里面装着枪和头盔是什么成语?全球[VPS测评]
- 疯狂猜成语 图猜成语一根棍子打草旁边一条蛇是什么成语?全球[VPS测评]
- 腾讯云服务器采购季活动被忽略的亮点,1 核 1G 内存 3M 带宽香港云香港VPS[主机]
- Zcloudme→$59.5 月 2*E5-2620v3 32G 内存 香港VPS[主机]
- 阿里云双十一拼团→云服务器年付 86 元起 2C4G3M 三年 799 全球[VPS测评]
- apache 设置 txt 文件直接下载而不是网页在线打开全球[VPS测评]
- 163 线路-ShockHosting→3.74 美元 KVM 1G 1全球[VPS测评]
- Justhost→俄罗斯 KVM 八折 87 卢布起 200M 无限流量全球[VPS测评]
- RAKsmart→日本站群服务器 50M 带宽 258IP 每月 241站群服务器[IP]
- WordPress5.2发布要求服务器配置不低于PHP5.6.20与My全球[VPS测评]
- SoftShellWeb 黑五促销 中国台湾大陆优化线路 1g内存 带5全球[VPS测评]
- Pacificrack为国外主机测评博客定制5折优惠码,不限制CPU全球[VPS测评]
- 免备案服务器对权重和网站排名有影响吗?全球[VPS测评]
- 美国信贷市场的痛苦将不亚于上世纪70年代的通胀时期美国VPS[主机]
- 147SEO采集器 CSS选择器写法案例全球[VPS测评]
- 江苏高防服务器哪里买?宿迁BGP、宿迁双线高防服务器的价格全球[VPS测评]
- 疯鱼云怎么样?香港CN2VPS首月14元,续费19元香港VPS[主机]
- JGKVM活动钜惠:美国cn2,香港cmi,大带宽vps,三网直连,10美国VPS[主机]
- 阿里云香港服务器多少钱一年?香港云服务器租用年付价格表香港VPS[主机]
- UCloud海外节点vps活动:香港、台湾等全球14个机房1折起,最低仅香港VPS[主机]
- 播放量破千万,点赞量破百万,你绝对想不到这三款多功能产品居然在TK上卖爆全球[VPS测评]
- 20个温暖心灵的问题,抖音,朋友圈都可以拿去发。全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-144491.html











