Need help getting category menu to format

by 14 replies
17
I have a theme which lists my pages in a horizontal menu, with drop down sub-menu items for the sub-pages. I wanted to add a menu item for categories, so I added the following code to my menu.php script ...

Code:
<?php 
wp_list_categories('sort_column=name&sort_order=asc&include=22,24,25&style=list&children=true&hierarchical=true&title_li=' . __('Memberships') . ' ''); 
?>
But, when the page was rendered, there was no margin between the menu item separator and the menu text, so I added spaces into the title so that the ('Memberships') part of the code became (' Memberships ')...

Code:
<?php 
wp_list_categories('sort_column=name&sort_order=asc&include=22,24,25&style=list&children=true&hierarchical=true&title_li=' . __(' Memberships ') . ' ''); 
?>
There was no change, as it appeared Wordpress had stripped the spaces out. So I did a little research, and added a div with float and margins ...

Code:
<div class="kwadded" style="float:left; margin-left: 10px; margin-right: 10px;">
<?php 
wp_list_categories('sort_column=name&sort_order=asc&include=22,24,25&style=list&children=true&hierarchical=true&title_li=' . __('Memberships') . ' ''); 
?>
</div>
I got the left margin spaced, but the right margin was again stripped out. So I played with it and found that by adding a space and a character to the ('Memberships') part of the code, making it ('Memberships |'), I could simulate a right margin. (I used the pipe symbol trying to be unobtrusive.) The code is ...

Code:
<div class="kwadded" style="float:left; margin-left: 10px;">
<?php 
wp_list_categories('sort_column=name&sort_order=asc&include=22,24,25&style=list&children=true&hierarchical=true&title_li=' . __('Memberships  |') . ' ''); 
?>
</div>
You can see the results at Consultant Supply Room (Note that the categories aren't listed unless you are logged in. This question is only about getting a margin to appear in this added menu item.)

Can someone advise me of a way to get the menu item to include the right margin? Or, how to find out what is causing the problem? I don't know if it is being stripped out by the theme or Wordpress.

Thanks in advance,
Kirk
#programming #category #format #menu
  • Hi Kirk, these types of problems always grab my attention.

    Can you tell me what theme this is based upon?
    That would help me try it out and have a fiddle with it.
    Which is another way of saying, I need to see more of what the menu.php file looks like.

    Or someone's going to come along and have an "Ah Ha" moment for you but I'm happy to help out if that doesn't happen.

    Cheers
    Tim
  • Hi Tim,

    I am using the iNews theme from iThemes (http://ithemes.com)

    I have a redistribution license to the theme if you want to take a look.

    And the aha's just aren't coming. I've piddled all evening.

    Thanks,
    Kirk
    • [1] reply
    • Hey Kirk - what time is it over there?

      Well whatever you are happy to do, I'm ok with.
      You've probably become a bit weary eyed staring at this...

      Just PM me the details - I'm around for a wee bit and I'd love to be able to have you go....WoooHooooo!

      If you are into that kind of thing and then Get Some Sleep!

      Cheers
      Tim
      • [1] reply
  • Thanks Tim,

    If you are able to do that, it might be a popular plugin. I see a lot of folks asking similar questions every now and then.

    Will be waiting with baited breath ...

    Kirk
    • [1] reply
    • Kirk,

      Check your email mate.
      It's got some "Stuff" in it that should do the trick for the time being.


      Cheers
      Tim
      • [ 1 ] Thanks
  • Great Job Tim ...

    It looks beautiful ...

    Any way to control which categories can be listed there? Say only certain ones in the list?

    I see the exclude=> action ... can the include => be used to limit the inclusions to the certain ones?

    However, that is a "picky" thing. It looks good enough I can live with it the way it is.

    Thanks 407 gazillion times over.

    Kirk
    • [1] reply
    • Hi Kirk,

      I'm glad it's working.

      I thought you might want to have the "Exclude" ability

      I'll give it a go at putting that in. I was just making sure what I got working so far was what you were after.

      Only a few more days at my Day JOB and then I'm a free agent. So I'll have a bit more time.

      Cheers
      Tim
  • Thanks again Tim,

    It's all beautiful. 'Exclude =>' worked out just fine. Took a minute or five to get my head in the right place. Now trying to figure out how to get the "No Categories" (which was edited to read "Please Log In") message to appear when no categories are allowed to show because they are protected.

    Will play and think.
    Kirk
    • [1] reply
    • Hi Kirk,

      I've seen you've been having a good play with the "new" bit.

      I'm learning up on making it a plug-in. Seems like fun...

      One thing I have noticed though and that is - the words fall out of the menu when the category name get's too long.

      A thought I had was to maybe use the category description field and have it display in the menu. That way you can keep your longer Categories showing up on the page and the abbreviated versions in the menu.

      That was something I found in my digging around. Or the simpler way is to just have shorter category names.

      I see now that's not an issue for you, but it's something to take into consideration.

      It's all fun and thanks for letting me help you out. I appreciate it.

      I've now started in on the Plugin writing side of things and this little exercise was just the ticket...

      Cheers
      Tim
  • Thanks Tim,

    I had the problem with long category names before and now that this is working, I just went in and edited the names so that they would fit. It is not related to the function ... but maybe your idea of using the description field might provide a solution.

    Thanks again, seventy or eighty times over.

    Kirk

Next Topics on Trending Feed

  • 17

    I have a theme which lists my pages in a horizontal menu, with drop down sub-menu items for the sub-pages. I wanted to add a menu item for categories, so I added the following code to my menu.php script ... Code: <?php wp_list_categories('sort_column=name&sort_order=asc&include=22,24,25&style=list&children=true&hierarchical=true&title_li=' . __('Memberships') . ' ''); ?> But, when the page was rendered, there was no margin between the menu item separator and the menu text, so I added spaces into the title so that the ('Memberships') part of the code became (' Memberships ')...