[不花钱站长]:从免费域名开始[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推荐网点击:714
【性价之王】【线路之王】【价格之王】【配置之王】
【免费之王】【香港首推】【梯子之王】【独服之王】
WordPress无插件实现相关内容调用功能

一般我们从WordPress后台获取的主题中,功能是比较少的,因为优质的主题一般都会需要付费。不过蜗牛也是比较喜欢获取简单的主题,然后加一些功能基本上可以实现基本的网站要求,本身网站是用来做内容的,并不是用来好看和丰富功能花哨的。

一般的主题中没有自带相关内容的功能,我们需要通过插件或者自己修改代码实现,使用插件一般会用到WordPress Related Posts插件,后台可以搜索和下载安装。蜗牛这里搜索到无需插件即可用代码实现的相关文章调用,也是通过TAG关键字匹配信息的。

第一、代码部分

<h3>这几篇文章你可能也喜欢:</h3>
<ul class=\\”related_posts\\”>
<?php
$post_num = 10;
$exclude_id = $post->ID;
$posttags = get_the_tags(); $i = 0;
if ( $posttags ) {
$tags = \\’\\’; foreach ( $posttags as $tag ) $tags .= $tag->term_id . \\’,\\’;
$args = array(
\\’post_status\\’ => \\’publish\\’,
\\’tag__in\\’ => explode(\\’,\\’, $tags),
\\’post__not_in\\’ => explode(\\’,\\’, $exclude_id),
\\’caller_get_posts\\’ => 1,
\\’orderby\\’ => \\’comment_date\\’,
\\’posts_per_page\\’ => $post_num,
);
query_posts($args);
while( have_posts() ) { the_post(); ?>
<li><a rel=\\”bookmark\\” h=\\”<?php the_permalink(); ?>\\” title=\\”<?php the_title(); ?>\\” target=\\”_blank\\”><?php the_title(); ?></a></li>
<?php
$exclude_id .= \\’,\\’ . $post->ID; $i ++;
} wp_reset_query();
}
if ( $i < $post_num ) {
$cats = \\’\\’; foreach ( get_the_category() as $cat ) $cats .= $cat->cat_ID . \\’,\\’;
$args = array(
\\’category__in\\’ => explode(\\’,\\’, $cats),
\\’post__not_in\\’ => explode(\\’,\\’, $exclude_id),
\\’caller_get_posts\\’ => 1,
\\’orderby\\’ => \\’comment_date\\’,
\\’posts_per_page\\’ => $post_num – $i
);
query_posts($args);
while( have_posts() ) { the_post(); ?>
<li><a rel=\\”bookmark\\” h=\\”<?php the_permalink(); ?>\\” title=\\”<?php the_title(); ?>\\” target=\\”_blank\\”><?php the_title(); ?></a></li>
<?php $i++;
} wp_reset_query();
}
if ( $i == 0 ) echo \\\'<li>没有相关文章!</li>\\’;
?>
</ul>

红色部分数字10表示调用10篇,我们可以根据实际调整。将代码丢到需要的相关文章位置模板中。

第二、调整 样式

我们可以根据实际的页面调整和添加 .related_posts 样式,包括行距等问题。



猜你可能想看的VPS


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

下一篇       上一篇