注册 登录 欢迎您到模板精:织梦模板_dede模板_免费网站模板_网站源码下载

建站经验_免费网站模板_dede模板

为大家提供织梦模板,dede模板,织梦网站建设,织梦网站建设教程,免费网站模板,网站源码下载,织梦模板下载,织梦自适应模板,织梦建站教程。

当前位置:首页 > 建站经验 >

WordPress调用指定分类下的文章

免费网站模板 2020-09-17 11:13 建站经验 评论
<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>