php Wordpress循环结构(wp)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Wordpress循环结构(wp)相关的知识,希望对你有一定的参考价值。

    <?
        query_posts( [
            'post_type' => 'custom_post_type_name',
            'category_name' => get_field( 'category' ),
            'posts_per_page' => 3,
            'orderby'   => 'date',
            'order' => 'DESC',
            'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
        ] )
    ?>
    <? while ( have_posts() ) : the_post() ?>
        <div class="loop__image rollover">
            <? if( has_post_thumbnail() ) : ?>
                <a href="<? the_permalink() ?>"><? the_post_thumbnail( 'home-thumb', [ 'class' => "img-responsive" ] ) ?></a>
            <? else : ?>
                <img src="/images/thumbnail.jpg" alt="<? the_title() ?>" class="img-responsive" />
            <? endif ?>
        </div>
        <div class="loop__content">
            <div class="loop__title">
                <h3><? the_title() ?></h3>
            </div>
            <div class="loop__teaser">
                <? the_excerpt(); ?>
            </div>
            <a href="<?php the_permalink() ?>" class="loop__read-more">Read More</a>
        </div>
    <? endwhile ?>
    <? wp_reset_query() ?>

以上是关于php Wordpress循环结构(wp)的主要内容,如果未能解决你的问题,请参考以下文章

wordpress自定义循环

PHP Wordpress面包屑基于wp_nav_menu而不是页面结构

在WordPress安装外部运行循环

关于wordpress5.0.1的一些目录结构

Wordpress目录结构

信息收集 -- WordPress网站