无插件实现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
- 华为云热门域名限时抢购 1 元起 com23 元 cn19 元全球[VPS测评]
- PacificRack→$9.99 年 KVM-1GB 13GB 2TB全球[VPS测评]
- $10.5 首年 512M 内存 10G SSD 500G 流量 1Gb全球[VPS测评]
- 蓝米云→29 元 月 1GB 内存 40GB SSD 空间 不限流量 1虚拟空间(主机)
- PHP 获取本周所有日期 PHP 获取当前时间所在周七天具体日期全球[VPS测评]
- 云创网络洛杉矶安畅 GIA 带宽免费升级,最高 300M 6 折起,美国美国VPS[主机]
- Psychz→$10 月 D525 4GB 内存 500GB 硬盘 30日本VPS[主机]
- FlashFXP 错误 530 Login incorrect 解决方法全球[VPS测评]
- 疯狂猜成语 图猜成语一个人气喘吁吁的在说话是什么成语?全球[VPS测评]
- WordPress 网站自定义广告位占位/出租代码全球[VPS测评]
- 搬瓦工VPS主机IP被封原因及应对方法全球[VPS测评]
- RangCloud 推出山东BGP NAT VPS全球[VPS测评]
- 搬瓦工2022新年全场12.22%循环折扣,续费同价,依然有效全球[VPS测评]
- PacificRack 便宜 VPS 512m内存 10G纯ssd 1T全球[VPS测评]
- Adobe Acrobat PDF 排版插件 Quite Imposin全球[VPS测评]
- XXIWEBHOSTING → 8$ 月 泰国 1C0.5G20G硬盘 全球[VPS测评]
- Wikihost(idc.wiki) → 香港HE线路促销 -非直连大香港VPS[主机]
- 桔子数据怎么样?便宜香港安畅CN2 VPS1核1G10M 28/月香港VPS[主机]
- 宏海数据9.9云服务器:香港VPS CN2线路1核1G 9.9/首月香港VPS[主机]
- 快云科技:2核2G3M香港云BGP/新界CN2云服务器,月付33元香港VPS[主机]
- edgenat:韩国cn2+香港cn2,VPS八折优惠,8核8G/50gWINDOWS
- UCloud海外云服务器促销:全场1折起,香港cn2vps最低年付150香港VPS[主机]
- 八点云主机怎么样?香港2核4G5M带宽云主机,98元/月;国内4核8G云香港VPS[主机]
- wikihost,微基主机:1核/1G/15G/100Mbps/香港vp香港VPS[主机]
- 厘米云,江苏移动100G高防云服务器,4核4G内存20M带宽79元/月全球[VPS测评]
- 腾讯云香港服务器价格,腾讯云香港云主机多少钱一年?香港VPS[主机]
- 95IDC :香港vps优惠活动,1核2G月付折后25元;香港物理机低至香港VPS[主机]
- edgeNAT:2021元旦vps促销_全场韩国/美国/香港VPS低至7韩国VPS[主机]
- 95idc怎么样?香港云主机1核2G2M仅50元/月;香港物理服务器8核香港VPS[主机]
- 快云科技:全场85折,香港CN2云服务器,月付24元起,不满意24小时无香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-144491.html











