当前位置:首页 >> 教程资讯 >> WordPress教程

WordPress调用指定分类下的文章

录入编辑:微科技 | 发布时间:2023-01-04
<ul> <?php $args=array( cat => 1, // 分类ID posts_per_page => 10, // 显示篇数

<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移除文章图片的宽度和高度属性
热门服务和内容

手机版

  • 官方微信

    扫码进入

  • 客服微信

  • 官方微信

    扫码添加

  • 高端网站设计,顶级互联网服务 Copyright © 2025 www.vikj.cn All Rights Reserved. 辽ICP备17005629号 XML地图 微科技
    电话咨询:0411-39550725
    在线客服咨询