显示页面中的自定义帖子类型帖子
问题描述:
我有一个名为“audio”的自定义帖子类型。要显示页面中的所有帖子,我写了下面的代码,但它不起作用。显示页面中的自定义帖子类型帖子
<?php
$post_type = "audioes";//post type names
echo "djnbfj";
$post_type->the_post();
// The Query
$the_query = new WP_Query(array(
'post_type' => $post_type,
'orderby' => 'post_date',
'order' => 'DESC',
'showposts' => 1,
));
// The Loop
?>
<?php
while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="issue-content">
<?php get_template_part('includes/breadcrumbs', 'page'); ?>
<?php if (has_post_thumbnail()) { the_post_thumbnail();}
get_template_part('loop-audio', 'page');
?>
</div><!--issue-content-->
<?php endwhile; ?>
</div> <!-- end #left_area -->
我如何获得帖子类型我想要上面写的自定义的。
答
是称为“音频”或“音频”的发布类型?您的$ post_type变量设置为“音频”。
答
我不确定get_template_part
行或echo
行正在做什么,但下面的代码应显示您的帖子类型。您的代码中还有帖子类型名称为“音频”,但您声明名称是“音频”。试试下面的代码,但是如果帖子类型被命名为“audioes”,那么您需要在下面的代码中更改该代码。您可以将<?php the_post_thumbnail(); ?>
和<?php the_content(); ?>
附加的div,span或其他HTML标记包装起来,以便为它们提供CSS样式。
<?php query_posts(array('post_type' => 'audio', 'posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC')); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="issue-content">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; wp_reset_query(); ?>
我的文章类型“audioes”。 – Ranjit