Exclude sub classified articles from WordPress classified archives

WordPress ten 3.1K Reading mode

 Exclude sub classified articles from WordPress classified archives

By default, WordPress will display sub classified articles on the classification page. If you want to display only the classified articles, but not the articles in the sub classification, you can use the following code.

In the main cycle of theme article archiving template:

  1. <? php  while  ( have_posts() ) : the_post();  ?>
  2. <? php  endwhile ;  ?>

Add above:

  1. <? php query_posts( array ('category__in' =>  array (get_query_var('cat'))));  ?>

Add below:

  1. <? php wp_reset_query();  ?>

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments ten    Visitors ten
    •  BanYuner
      BanYuner five

      Isn't it said that the use of query_posts is not recommended and wp_query is recommended?

      •  Inspirational Quotes
        Inspirational Quotes six

        Learned,

        •  Inspirational Quotes
          Inspirational Quotes six

          sofa.

          •  Win7en Paradise
            Win7en Paradise seven

            Can't I grab the sofa?

            •  Yaxi
              Yaxi four

              Practical. There are still many things to do in WordPress directory filtering

              •  Happy News
                Happy News three

                The article is dry

                •  Fun Fruit Net
                  Fun Fruit Net three

                  I don't understand the program, it's all Baidu's groping

                  •  Cabin
                    Cabin one

                    Collected~

                    •  Today's headlines
                      Today's headlines three

                      The article is good, support it

                      •  Fun Fruit Net
                        Fun Fruit Net three

                        Thanks for sharing. What's the purpose of this setting? Since sub categories are set, the real content is not allowed, just to look good? Are there many columns?

                       anonymous

                      Comment

                      Anonymous netizens
                       :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                      Drag the slider to complete validation