【问题标题】:display the custom post type post in page在页面中显示自定义帖子类型帖子
【发布时间】:2012-12-06 18:32:53
【问题描述】:

我有一个名为“音频”的自定义帖子类型。为了在一个页面中显示所有帖子,我编写了下面的代码,但它不起作用。

          <?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 -->

我怎样才能得到我想要上面写的自定义的帖子类型。

【问题讨论】:

    标签: wordpress custom-post-type


    【解决方案1】:

    帖子类型是“音频”还是“音频”?您的 $post_type 变量设置为“audioes”。

    【讨论】:

      【解决方案2】:

      我不确定get_template_part 行或echo 行在做什么,但下面的代码应该会显示您的帖子类型。您的代码中的帖子类型名称也为“audio”,但您声明名称为“audio”。试试下面的代码,但如果帖子类型被命名为“音频”,那么你需要在下面的代码中更改它。您可以在 &lt;?php the_post_thumbnail(); ?&gt;&lt;?php the_content(); ?&gt; 周围包裹额外的 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(); ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-20
        • 2019-05-08
        • 1970-01-01
        • 2012-11-11
        • 1970-01-01
        相关资源
        最近更新 更多