• Resolved creed3000

    (@creed3000)


    hello
    i have been able to install child theme to make edits
    but not making much progress ..

    /*
    Theme Name:     twenty child 1
    Theme URI:      https://www.psychic3000.com/
    Description:    Child theme for the Twenty Twelve theme
    Author:         Creed masters
    Author URI:     https://www.psychic3000.com/
    Template:       twentyeleven
    Version:        3.4.2
    */
    /* Import layout */
    @import url(../twentyeleven/style.css);
    
    a{ color: #254655; }
    body{
    background: #727D82;
    }  
    
    header#branding{
    background: #29305C;
    color: #B3BDC1;
    }  
    
    header#branding h1, header#branding h2, header#branding a{ color: #B3BDC1; }  
    
    #respond{ background: #E7DFD6; } 
    
    <?php wp_list_categories('&title_li=&depth=1'); ?>

    to make sure my child theme is working i did a test to change background color of blog .. ( its working )

    im trying to hide sub categories from main menu
    ive tried many options but no luck .. last attempt ( fail )

    <?php wp_list_categories('&title_li=&depth=1'); ?>

    im new to this so just getting that child working was a big deal to me .. So any help would be great … ( thank you )

Viewing 11 replies - 1 through 11 (of 11 total)
  • php code does not belong in style.css.

    the main menu is not made with wp_list_categories() but with wp_nav_menu();

    if you see sub category items in the main menu, then you probably have added tham into the custom menu at some point, where you can remove them again; https://codex.www.ads-software.com/Appearance_Menus_Screen

    Thread Starter creed3000

    (@creed3000)

    thank you for your reply – however as i said just making the child theme was a huge step for me .. so im not sure what your saying i need to do. i thought the main reson to make child theme was so i can make all the mods thier ( so im confused )

    do i create another file ( A functions.php file )in that child folder or do i take that php code & insert it into the actual
    functions.php file of the parent theme ????

    will this code remove sub categories from my main menu ..
    <?php wp_list_categories('&title_li=&depth=1'); ?>

    i need simple instruction,
    im new to this but would like to learn
    So more help would be great … ( thank you )

    are you using the custom menu?

    by default, i.e. if the custom menu is not activated, Twenty Eleven only shows pages in the menu;

    if you are seeing category links, then I would assume that you are indeed using the custom menu; and you would need to make the changes there.

    please post a link to your site to illustrate the problem.

    Thread Starter creed3000

    (@creed3000)

    are you using the custom menu? ( i think so )
    here is the blog ( brand new )
    https://psychic3000.com/wordpress/

    will be doing horoscopes, daily, weekly, monthly, etc
    daily horoscope will be main category
    then i will have 12 sub categories

    weekly horoscope will also be main category
    then i will have 12 sub categories
    12 sub caterories are zodic signs

    so i need to hide sub categories form main menu
    also need to hide post from horoscopes from front page

    thank you for the reply & trying to help

    so i need to hide sub categories form main menu

    you seem to be referring to the sidebar categories widget;
    to suppress sub categories in the categories widget:

    if you don’t have a functions.php in your child theme yet, create a new file functions.php in the child theme, and add in the first line:

    <?php

    https://codex.www.ads-software.com/Child_Themes#Using_functions.php

    then add:

    add_filter('widget_categories_args','custom_category_widget_args');
    function custom_category_widget_args($args) {
    $args['depth'] = '1';
    return $args;
    }

    need to hide post from horoscopes from front page

    what categories are these?

    generally https://codex.www.ads-software.com/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page

    i.e. you will need to add the code into functions.php, with the category ID numbers changed to the ones you want to exclude:

    function exclude_homepage_categories( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-1,-1347' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_homepage_categories' );
    Thread Starter creed3000

    (@creed3000)

    allright, thats some useful info
    thank you for taking the time to be so helpful

    ok, i created the functions.php
    and copied your code into it

    <?php
    
    add_filter('widget_categories_args','custom_category_widget_args');
    function custom_category_widget_args($args) {
    $args['depth'] = '1';
    return $args;
    } 
    
    function exclude_homepage_categories( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-15' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_homepage_categories' );

    the post from category 15 & all sub categories did dissapear from the front page ( which is great !!! ) however the sub categories still show in the side bar main menu

    So more help would be wonderful … ( thank you for your time )

    the sub categories still show in the side bar main menu

    the ‘depth’ parameter seems only be working when the output is set to ‘hierarchical’;

    try to change this line:

    $args['depth'] = '1';

    to these two lines:

    $args['depth'] = 1;
    $args['hierarchical'] = 1;
    Thread Starter creed3000

    (@creed3000)

    ummmmmmm yes sir OMG ( it worked )

    but before i go & mark this resolved i will go ahead & ask
    if i want to hide additional sub categories
    i would edit this line

    $query->set( 'cat', '-15, -16' );

    i would add , -subcategory#, etc’ );

    and the last question ..
    what if i want to hide a main category ??

    you did a super job & are an awesome moderater !!!
    thank you so much for helping me out !!!

    what if i want to hide a main category ??

    you could also add it to the list;

    I assume that this would also hide all sub categories of that main category at the same time…

    if you wan’t to hide a main category, but allow the sub categories of that main category, this is getting meore complex;
    try using:

    $query->set( 'category__not_in', array(15,16);

    for example, this would exclude cat 15 and cat 16, but allow any of their sub categories (untested; I would verify this in a test blog before going live).

    Thread Starter creed3000

    (@creed3000)

    yes, i would just add it $query->set( ‘cat’, ‘-15, -16’ );
    i was just making it more complicated than need be
    yes if i hid main category i would hide sub category

    you’ve gone above & beyond
    your are a great source of wisdom !!! ( thank you )

    alchymyth – You are amazing! I’ve been searching for hours how to “Hide child categories” – Nothing has worked until I came across this thread. This may be out of place, But your answers are helping more people than just the thread starter!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘child theme – unable to hide sub categories main menu’ is closed to new replies.