[不花钱站长]:从免费域名开始[0元] Oracle永久免费VPS[0元] VPS环境搭建免费脚本[0元] 秒变大盘挂载免费网盘[0元] 小白免费采集器1天500W[0元] CF免费DNS+CDN服务[0元]
[零基础网赚]:撸本站免费源码[0元] 网站强引免费蜘蛛法[0元] 图片视频文件免费存储[0元] 外链轻松发布免费友链[0元] 入坑免费教程学习源代码[0元] 网上百种+赚钱联盟推荐[?元]

↑↑VPS推荐网 WWW.VPS.COM.IN 稳定 便宜 免备案↑↑


您现在的位置是:首页 > 全球[VPS测评] >  WordPress相关,便宜vps,相关文章,VPS优惠,国外永久免费VPS

无插件实现WordPress相关文章调用方法

全球[VPS测评]来源:VPS推荐网点击:474
【性价之王】【线路之王】【价格之王】【配置之王】
【免费之王】【香港首推】【梯子之王】【独服之王】
无插件实现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相关]历史优惠活动内容
  • 无插件实现WordPress相关文章调用方法

  • 猜你可能想看的VPS


    转载请注明原文地址:http://140.238.13.167:12355/read-144491.html

    下一篇       上一篇