WordPress的自定义帖子没有显示特色

问题描述:

我在创建新的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> 

请更改第一本

'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