• I wanted to have a category header using a post (for ease of adding, updating, …) So that for a new header post I should select the category ‘header’ AND the category it describe.

    So I went with this code:
    in theme-child/functions.php :

    add_action( 'pre_get_posts', 'exclude_category' );
    function exclude_category($query){
      global $wp_the_query;
      if (!$query->is_admin && $wp_the_query == $query ) {
        $query->set( 'cat', -68 );
      }
      return $query;
    };

    here the ‘header’ category (68) is excluded from every pages except admin pages

    and in category.php I added before calling the loop

    if (paged < 2) :
    	 $apropos_query = new WP_Query($query_string . '&cat=68');
    	 while ( $apropos_query->have_posts() ):
                    $apropos_query->the_post();
    	 	the_title();
    	 endwhile;
     endif;

    here the new query to show the category header post

    Was this a proper way to do it, is there a better/simpler way ?

Viewing 1 replies (of 1 total)
  • Thread Starter scrupulosis

    (@scrupulosis)

    Took a day to find previous solution :'(

    And it was simple as that

    <?php if (paged < 2 && category_description()!='') : ?>
          <div class="cateDesc">
              <?php echo category_description()?>
          </div>

    And if you need html code in your category description there’s a plugin to do so.

Viewing 1 replies (of 1 total)
  • The topic ‘category header without category template’ is closed to new replies.