wordpress - How to list post of certain category (only one category lets say cat id = 5 ) only on blog listing page? -


i need list posts of category on blog listing page , let's of category id 5. need plugins or function.php file. not want change template files, think blog listing on index.php.

i used parse_query hook following. affect other places . menu bar gone. please me. thank you.

 add_filter( 'parse_query', 'pp_posts_filter' );    function pp_posts_filter( $query ){      $query->query_vars['cat'] = 5;   } 

to make query changes specific main query , not secondary ones menus or sidebars etc. use is_main_query function i.e.

 add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' ); function foo_modify_query_exclude_category( $query ) {     if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'cat' ) )         $query->set( 'cat', '-5' ); } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -