2012-12-06 294 views
0

我有一個名爲「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 --> 

我如何獲得帖子類型我想要上面寫的自定義的。

回答

0

是稱爲「音頻」或「音頻」的發佈類型?您的$ post_type變量設置爲「音頻」。

+0

我的文章類型「audioes」。 – Ranjit

0

我不確定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(); ?> 
相關問題