[英]can't view custom post type posts in WP home page
我正在嘗試在WordPress中查看自定義帖子類型的帖子,並停留在下面的代碼中。
$args = array(
'type' => 'theslider',
'orderby' => 'date',
'order' => 'DESC',
'cat' => 23
);
$lasts = new WP_Query( $args );
if( $lasts->have_posts() ):
while( $lasts->have_posts() ): $lasts->the_post();
the_title( sprintf('<a href="%s"><div class="pt10 title">', esc_url( get_permalink() ) ),'</div></a>' );
endwhile;
endif;
wp_reset_postdata();
此代碼適用於默認帖子類型。 而且“自定義帖子類型”功能在管理面板中效果很好。
如何在WordPress主頁上查看自定義帖子類型的帖子。
得到它了。 在此處發布以供將來參考。
<?php
$args = array(
'post_type'=> 'theslider',
'orderby' => 'date',
'order' => 'DESC'
);
$the_query = new WP_Query( $args );
if($the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
else:
echo '<p>Nothing Here.</p>';
endif;
wp_reset_postdata();
?>
而已。 它會獲取並查看自定義帖子類型的帖子:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.