当前位置: 首页 > 阿里云优惠 > 阿里云服务器优惠>> WordPress如何调用同分类随机文章 – WordPress 教程

WordPress如何调用同分类随机文章 – WordPress 教程


WordPress如何调用同分类随机文章 – WordPress 教程
WordPress

在适当的位置显示调用随机文章可以促进网站内链,增加文章阅读点击量,有利于SEO,网上大部分Wordpress调用随机文章代码都是基于全站文章,这里发一个调用同分类随机文章的代码。

将下面代码放到主题文章页面single模板或者边栏sidebar模板适当位置即可:

<ul>    <?php    $cat = get_the_category();    foreach($cat as $key=>$category){        $catid = $category->term_id;    }    $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid );    $query_posts = new WP_Query();    $query_posts->query($args);    while ($query_posts->have_posts()) : $query_posts->the_post();    ?>    <li><a href="https://xyy1.com/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>    <?php endwhile;?>    <?php wp_reset_query(); ?></ul>

服务器购买/咨询热线:1563700917115617636856

本文链接:http://www.sqxnmj.com/alfwq/28261.html
tags:
腾讯云服务器特惠

  • 关注微信
是否收录:

猜你喜欢

微信公众号