• Resolved enviado

    (@enviado)


    Hi!

    I have a problem with my categories menu. As you can see in my web: http://www.enviadoespecial.es/wordpress i have an horizontal menu with the categories (Inicio=home, etc).

    There are 2 issues:

    – I don’t want this categories order. Now it shows 5 of the 7 categories of my web randomly and i want to order by id

    – It doesn’t show all the categories, just 5 of 7 and all of them have posts…

    This is my code in the header.php:

    <!-- BEGIN categorias -->
    		<ul class="pages">
    		<li><a href="<?php echo get_option('home'); ?>">Inicio</a></li>
    		<?php dp_list_categories(); ?>
    		</ul>
    		<!-- END categorias -->

    I don’t know whats wrong and why my theme uses dp_list_categories instead wp_list_categories. If i put wp_list_categories it shows the categories but with a completely different style…

    Any help please? Thanks!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Google says that code only retrieves categories with posts in them, and only display parent categories.

    You can customize wp_list_categories somewhat. See http://codex.wordpress.org/Template_Tags/wp_list_categories

    I THINK this might do it:
    wp_list_categories('orderby=id');

    Of course, it depends what ‘5 of 7’ means. If you only want to show parent cats, then add &depth=1 to the params etc etc.

    Find the function dp_list_categories in either your theme folder and see if it accepts any of the template tag, wp_list_categories(), arguments.

    If you continue this thread, please provide a link to download the theme you are using.

    Thread Starter enviado

    (@enviado)

    Thanks a lot for the help.

    This is the way i solved it:

    In the functions.php of my theme i found:

    # Displays a list of categories
    function dp_list_categories($exclude='') {
    	if (strlen($exclude)>0) $exclude = '&exclude=' . $exclude;
    	$categories = get_categories('hide_empty=1'.$exclude);
    	$first = true; $count = 0;
    	foreach ($categories as $category) {
    		$count++; if ($count>5) break; // limit to 5
    		if ($category->parent<1) {
    			if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
    			?><li<?php echo $f; ?>>
    			<a href="<?php echo get_category_link($category->cat_ID); ?>"><?php echo $category->name ?><?php echo $raquo; ?></a></li>
    			<?php
    		}
    	}
    }

    And i changed for:

    # Displays a list of categories
    function dp_list_categories($exclude='') {
    	if (strlen($exclude)>0) $exclude = '&exclude=' . $exclude;
    	$categories = get_categories('orderby=ID&hide_empty=1'.$exclude);
    	$first = true; $count = 0;
    	foreach ($categories as $category) {
    		$count++; if ($count>7) break; // limit to 7
    		if ($category->parent<1) {
    			if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
    			?><li<?php echo $f; ?>>
    			<a href="<?php echo get_category_link($category->cat_ID); ?>"><?php echo $category->name ?><?php echo $raquo; ?></a></li>
    			<?php
    		}
    	}
    }

    As you can see, i put 7 as the limit and get_categories the orderby=id.

    Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem order my categories’ is closed to new replies.