Wordpress显示文章分类及分类链接

2022-09-14 16:13:13 浏览数 (1)

代码语言:javascript复制
<ul class="unorderList blogpage">
    <?php
    $args = array(
            'post_type'=>'post'
    );
    
    $query = new WP_Query($args);
    ?>

<?php if($query->have_posts()): ?>
    <?php while($query->have_posts()):$query->the_post();?>
    <li>
        <div class="blogImg">
            <?php the_post_thumbnail()?>
            <div class="blog_date"><?php the_time('M,d,Y')?></div>
        </div>
        <div class="blog_sec">
            <h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
            <span style="overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp:2;-webkit-box-orient: vertical;"><?php the_excerpt();?></span>
            <div class="readmore">
                <!--  文章分类  -->
                <?php
                $the_post_category = get_the_category($post->id);
                foreach ($the_post_category as $category){
                    echo "<a href=".get_category_link($category->term_id).">".$category->cat_name."</a>";
                }?>

            </div>
        </div>
    </li>
<?php endwhile; endif; wp_reset_postdata();?>


</ul>

0 人点赞