Php 如何在Wordpress中显示有关帖子的简短描述?

Php 如何在Wordpress中显示有关帖子的简短描述?,php,wordpress,Php,Wordpress,我使用Wp_query()获取帖子。然后显示post_缩略图和标题 <?php $args = array( 'type' => 'post', 'category__in' => '23', 'posts_per_page' => 1, 'offset' => 2, ); $lastBlog = new WP_Query($args); if ($lastBlog->have_posts()): while ($l

我使用Wp_query()获取帖子。然后显示post_缩略图和标题

<?php

$args = array(
    'type' => 'post',
    'category__in' => '23',
    'posts_per_page' => 1,
    'offset' => 2,
);

$lastBlog = new WP_Query($args);
if ($lastBlog->have_posts()):
    while ($lastBlog->have_posts()): $lastBlog->the_post();

        if (has_post_thumbnail()) {
            the_post_thumbnail();
            the_title(sprintf('<h4 class="entry-title"><a href="%s">', esc_url(get_permalink())), '</a></h4>');
        }

    endwhile;
endif;
wp_reset_postdata();
?> 

有两种方法可以做到这一点。一种方法是只输出文章的内容,并在文本
中添加一个“Read more”标记,然后通过后面的“Read more”按钮输出文本:

<?php 
$args = array( 
    'type' => 'post',
    'category__in' => '23',
    'posts_per_page' => 1, 
    'offset' => 2,
    );

$lastBlog = new WP_Query( $args ); 

if( $lastBlog->have_posts() ):
    while( $lastBlog->have_posts() ): $lastBlog->the_post();
        if ( has_post_thumbnail() ) {  
    echo '<div class="post_wrapper">';
    the_post_thumbnail();
    the_title( sprintf('<h4 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h4>' );
    the_content( 'Read more ...' );
    echo '</div>';
        }
    endwhile;
endif;

wp_reset_postdata();      
?> 
你可以选择使用哪一个


另外,如果没有缩略图,您确定不想显示帖子吗?如果没有,只需将if条件移动到标题之前,您就应该拥有文章,即使您没有设置文章缩略图。如果你是这样想的,那么一切都没问题有两种方法可以做到这一点。一种方法是只输出文章的内容,并在文本
中添加一个“Read more”标记,然后通过后面的“Read more”按钮输出文本:

<?php 
$args = array( 
    'type' => 'post',
    'category__in' => '23',
    'posts_per_page' => 1, 
    'offset' => 2,
    );

$lastBlog = new WP_Query( $args ); 

if( $lastBlog->have_posts() ):
    while( $lastBlog->have_posts() ): $lastBlog->the_post();
        if ( has_post_thumbnail() ) {  
    echo '<div class="post_wrapper">';
    the_post_thumbnail();
    the_title( sprintf('<h4 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h4>' );
    the_content( 'Read more ...' );
    echo '</div>';
        }
    endwhile;
endif;

wp_reset_postdata();      
?> 
你可以选择使用哪一个

另外,如果没有缩略图,您确定不想显示帖子吗?如果没有,只需将if条件移动到标题之前,您就应该拥有文章,即使您没有设置文章缩略图。如果你是这样想的,那么一切都没问题D