欢迎来到站长天空!

WordPress

当前位置: 主页 > CMS教程 > WordPress

WordPress如何调用指定分类目录文章

时间:2025-11-11 14:34:32|栏目:WordPress|点击:

WordPress如何调用指定分类目录文章?其实这个问题很简单,通过以下这段代码即可实现。

使用方法:把以下代码添加到你希望显示的地方,并修改相关参数即可。

<ul>
<?php
    $args=array(
        'cat' => 1,   // 分类ID
        'posts_per_page' => 10, // 显示篇数
    );
    query_posts($args);
    if(have_posts()) : while (have_posts()) : the_post();
?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> //标题
        <span>
        <?php if (has_excerpt()) {
                echo $description = get_the_excerpt(); //文章编辑中的摘要
            }else {
                echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
            } ?>
        </span>
    </li>
<?php  endwhile; endif; wp_reset_query(); ?>
</ul>


上一篇:WordPress如何自定义文章标题颜色

栏    目:WordPress

下一篇:WordPress如何调用显示文章最后一次更新时间?

本文标题:WordPress如何调用指定分类目录文章

本文地址:https://zz.feitang.co/CMSjiaocheng/25923.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号