有没有办法在WordPress中的div中调用自定义帖子内容

时间:2020-05-19 21:59:26

标签: wordpress wordpress-theming custom-post-type wordpress-shortcode

我正在创建自定义帖子类型的简码,并且工作正常,但是当我尝试在div中调用自定义帖子内容时遇到问题,它显示了整个简码区域之外的内容

以下是简码的代码enter image description here

add_shortcode('portfolios-list', 'pf_portfolio_list');

function pf_portfolio_list(){
    $args = array(
        'post_type' => 'portfolios',
    );

    $query  = new wp_query($args);

    if($query->have_posts()) :

        $events   .= '<div class="owl-carousel owl-theme">';

        while($query->have_posts()) :

            $query->the_post(); 

            $events    .= '<div class="item">
               <div class="row">
                 <div class="col-lg-7 cust-v-align">
                   <div class="media-img"> '.get_the_post_thumbnail($r->ID, array(600,600)).' </div>
                 </div>
                 <div class="col-lg-5 pl-5">
                   <div class="project-info mt-5">'.the_content().'</div>
                 </div>
              </div>
           </div>';

        endwhile;

    wp_reset_postdata();

    $events   .= '</div>';

    endif;

    return $events;

}

enter image description here

1 个答案:

答案 0 :(得分:0)

当我使用 get_the_content()而不是the_content()

时,效果很好