2014-11-06 85 views
1

我在創建新的WordPress主題時遇到了一個奇怪的問題。所以也許因爲我一整天都在這裏,但需要看看是否有人能夠發現我的錯誤,或者看看有什麼問題。WordPress的自定義帖子沒有顯示特色

我想根據類別的名稱顯示'精選'的帖子,只顯示一個,如果這已在wp-admin部分檢查。然而,我在代碼中定義了這一點,但它顯示了最新的帖子,而不管它是否被顯示。

<?php 

      $args = array(
       'post_type' => 'post', 
       'category_mame' => 'featured', 
       'posts_per_page' => 1 
      ); 

      $the_query = new WP_Query($args); 

      ?> 

      <?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 

      <div class="push_2 grid_10 omega clearfix"> 
       <article> 

        <?php get_template_part('content', 'post'); ?> 

       </article> 
      </div> 

     <?php endwhile; endif; ?> 

    </div> 

回答

0

請更改第一本

'category_mame' => 'featured', 

'category_name' => 'featured', // name not mame 

Here是內置的WordPress的狀態參數。

我不知道這是不是正是你所尋找的東西,但你可以查詢狀態後您的文章,如果您添加post_status$args -array:

$args = array(
      'post_type' => 'post', 
      'category_mame' => 'featured', 
      'posts_per_page' => 1, 
      'post_status' => 'publish', //or 'draft', 'trash', 'pending', ... (see the link above) 

     ); 


希望它能幫助。

+0

噢,我的,這是非常尷尬的,錯字是問題('mame')。但也感謝您的額外信息。 – Dan 2014-11-06 15:44:51

+0

@丹我很高興聽到它現在正在工作 – pbaldauf 2014-11-06 15:49:01

相關問題