• Resolved matthieu14

    (@matthieu14)


    Hello all !

    I have been using Customizr theme for a while and it is really amazing. I would like first to thank the developers who made it possible and affordable for anyone :).

    Quick question, I found out that the menus (both header & footer) are not appearing on my category pages while it is appearing on single pages and single posts.

    Is it possible with a simple snippet to add them also to category pages ?

    Here is a link to one of the categories of my website where you can see that the menus both in the header & footer are not appearing.

    Thank you in advance for anyone who will help,
    Best,
    Matthieu

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,
    I find that the menu is displayed in some categories like Cours de truc.

    Have you done any customization of category pages?

    Thread Starter matthieu14

    (@matthieu14)

    Hello Menaka S,

    Thanks for your answer.

    You are right, the menu is displayed in some categories like the one you have quoted ! But I have no customized category page.

    Yet, I think we have a clearer picture of the problem now : the menu is not displayed only on “sub-category” pages. Indeed, on categories like Cours de turc or Themes, the menu is displayed but in categories included into other categories such as Niveau 1 which belongs to Cours de turc, the menu is not displayed.

    How can we fix that ?

    Thank you in advance !

    Hi,
    1. Have you altered the query in any way?
    2. Can you try disabling all plugins and then check?

    Thread Starter matthieu14

    (@matthieu14)

    Hello Menaka,

    1. Yes I have altered the query for this kind of pages using the following snippet:

    add_action('pre_get_posts','alter_query');
    function alter_query($query) {
    	//gets the global query var object
    	if (is_category('niveau-1')==false and is_category('niveau-2')==false and is_category('niveau-3')==false and is_category('niveau-4')==false and is_category('niveau-5')==false and is_category('niveau-6')==false)
    		return;
    
    	$query-> set('orderby' ,'meta_value_num');
        $query-> set('meta_key','ordon');
        $query-> set('order','ASC');
    }

    The idea is to order the posts of these subcategories by a meta-key called “ordon”. Is it possible that it makes the menu disappear?

    2. I tried to disable all of them, it does not change anything

    Hi,
    Can you try commenting
    1)the if condition
    2)the entire alter query
    to check if the problem is caused by this code?

    Thread Starter matthieu14

    (@matthieu14)

    Hello Menaka,

    Sorry for responding late, I was off for a few days.

    Here are my comments :

    add_action(‘pre_get_posts’,’alter_query’);
    function alter_query($query) {
    // if the pages do not belong to the category “niveau-1”, “niveau-2” up to “niveau-6”, do nothing
    if (is_category(‘niveau-1’)==false and is_category(‘niveau-2’)==false and is_category(‘niveau-3’)==false and is_category(‘niveau-4’)==false and is_category(‘niveau-5’)==false and is_category(‘niveau-6’)==false)
    return;
    // if the page belongs to one of the aforementionned categories do the following
    // modify the query by ordering the posts by a meta_key called “ordon” that I have created for the posts belonging to the aforementionned categories.
    // and order by an ascending order
    $query-> set(‘orderby’ ,’meta_value_num’);
    $query-> set(‘meta_key’,’ordon’);
    $query-> set(‘order’,’ASC’);
    }

    It is likely that this query is causing the problem since the menu is not displayed only for the categories concerned by the if condition..

    Is it clearer ?
    Thanks in advance,

    M.

    Hi,
    Nav menus are also generated by a WP_Query, so in your pre_get_posts callback function you need to check if the $query you’re altering is the main query.

    Please add this to the beginning of your alter_query() function.

    if ( ! $query->is_main_query() )
        return $query;
    Thread Starter matthieu14

    (@matthieu14)

    Thanks a lot Menaka, it is solved !

    Glad ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding Menu on Category Pages’ is closed to new replies.