douche3244 2014-11-06 15:29
浏览 65
已采纳

Wordpress自定义帖子没有显示特色

I have come across a strange problem when creating a new wordpress theme. So maybe because I have been at this all day but need to see if anyone can spot my error or see what is the problem.

I am trying to display 'featured' posts as per the name of the category and show only the one if this has been checked in the wp-admin section. Yet I am defining this within the code but it shows the latest post instead regardless of it being featured or not.

<?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>
  • 写回答

1条回答 默认 最新

  • dousendun8411 2014-11-06 15:43
    关注

    Please change first this

    'category_mame' => 'featured', 
    

    to

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

    Here are the built-in status parameters of Wordpress.

    I don't know if this is exactly the thing you are searching for but you can Query your post after status if you add post_status to the $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)
    
            );
    


    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line