• Resolved tomasi514

    (@tomasi514)


    Can someone help me with this?
    I am displaying a menu by using this code:
    ‘wp_list_categories(‘orderby=name&use_desc_for_title=1&depth=1&hierarchical=1&style=0&hide_empty=0&child_of=’.$cat4);’

    Here is an exemple of what I want to do:
    menu1
    menu2
    menu3 (automatically highlighted or different style because we are on menu3 category page)
    menu4

    Oups, is that clear enough?

Viewing 11 replies - 1 through 11 (of 11 total)
  • I would use get_categories with the same basic parameters – that will give an array of the categories that you can then build your own list using ul and li – and allow you to change the style on the choice you want.

    Thread Starter tomasi514

    (@tomasi514)

    Thanks for your answer myinstinct, with this menu, I need to list sub categories under a specific category, that explains the “child_of=’.$cat4” which has to be dynamic.
    Can I do this with get_categories?

    Thread Starter tomasi514

    (@tomasi514)

    All right, seams to be a possible solution, I do not know the function very well, can you give me an example or a link that explains how to rebuild a menu after using this function?

    Thread Starter tomasi514

    (@tomasi514)

    Thanks myinstinct, I tried to manipulate a bit the drop-down menu as shown on the page you gave me but I am not sure it will help me. Still, my drop-down box appears, with the right subcategory names for the different options.

    I guess at least the start may be:

    $categories=  get_categories('orderby=name&use_desc_for_title=1&depth=1&hierarchical=1&style=0&hide_empty=0&child_of='.$cat4);
      foreach ($categories as $cat_z) {...

    I now have to create a simple horizontal menu using ul an li, can you help me a bit more?

    I haven’t tested this, but it should look something like

    echo '<ul>';
    foreach ($categories as $cat) {
      	$option = '<li>' . $cat->category_nicename . '</li>';
    	echo $option;
    }
    echo '</ul>';

    You may want to make the $cat->category_nicename a link as well, so

    $option = '<li><a href="page to link to here">' . $cat->category_nicename . '</a></li>
    ';
    Thread Starter tomasi514

    (@tomasi514)

    cool!
    Thanks a lot myinstinct.

    Thread Starter tomasi514

    (@tomasi514)

    works fine!
    Here we go:

    $categories=  get_categories('orderby=name&use_desc_for_title=1&depth=1&hierarchical=1&style=0&hide_empty=0&child_of='.$cat4);
    echo '<ul>';
    foreach ($categories as $catz) {
        $option = '<li><a href="./?cat=' . $catz->cat_ID . '">' . $catz->cat_name . '</a></li>';
    	echo $option;
    }
    echo '</ul>';
    Thread Starter tomasi514

    (@tomasi514)

    Here is my 95% final code:

    <div id="navmenu2">
    
    <?php
    //wp_list_categories('orderby=name&use_desc_for_title=1&depth=1&hierarchical=1&style=0&hide_empty=0&child_of='.$cat4);
    $categories=  get_categories('orderby=name&use_desc_for_title=1&depth=1&hierarchical=1&style=0&hide_empty=0&child_of='.$cat4);
    
    echo '<ul>';
    foreach ($categories as $catz) {
        $option = '<li><a href="./?cat=' . $catz->cat_ID . '">' . $catz->cat_name . '</a></li>';
        $option2 = '<li id="tralala"><a href="./?cat=' . $catz->cat_ID . '">' . $catz->cat_name . '</a></li>';
    	$cat_numb= $catz->cat_ID;
    //echo $cat_numb;
    
    	if ( $cat_numb==$catid)
    				{
    				echo $option2;
    				}
    				 else
    				{
    				echo $option;
    				} 
    
    }
    echo '</ul>';?>
    
    </div>

    My only remaining problem is that separation between each line is now more important than when I did not use

      and

    Thread Starter tomasi514

    (@tomasi514)

    ul and li…

    Thread Starter tomasi514

    (@tomasi514)

    I managed to finish this with my css, the main code is up there.
    Again, thank you myinstinct, I close the post.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘page awareness with wp_list_categories?’ is closed to new replies.