WordPress.org

Ready to get started?Download WordPress

Forums

Help Needed Customising 'Categories' Function (4 posts)

  1. newbee
    Member
    Posted 8 years ago #

    Hi,

    As part of customising the way categories are displayed in my sidebar, I need to be able to display just the first 3 categories, ordered alphabetically (ascending) & show the number of posts for each of these categories.

    Having read through the codex, the best thing I've been able to come up with is:

    <?php WP_list_cats (' sort_column=name&optioncount=1&exclude=x');?>
    where x=the list of category ids I want to exclude

    Although this will work, I have a long list of categories that need to be excluded, so it's a bit clumsy, added to which, everytime I add a category, I'll have to alter the code.

    What I really want is to be able to say exclude x where where x=all categories with ids greater than 3, but my limited understanding of the syntax for this function tell me I can't do this...or can I?

    Can anyone suggest an elegant solution?

    Thanks

  2. skulled
    Member
    Posted 8 years ago #

    How are you with PHP?

    If you are familiar and comfortable with programming in PHP, what you could do is use the list_cats function with recurse setting set to TRUE which would return the list, and then use to PHP to remove all categories that you do not need, and display the rest

    Cannot think of a more 'elegant' way right now .. let me know if that works, if it doesn't I can try see if something else is possible.

  3. newbee
    Member
    Posted 8 years ago #

    Thanks, but I am neither familiar nor comfortable with PHP.

  4. skulled
    Member
    Posted 8 years ago #

    That is not so good .. ;)

    In that case I am afraid I don't see any other methods of doing what you want, with builtin WP functions ..

    Maybe someone else can clarify this, but I think custom code is the only way you are going to achieve what you want.

Topic Closed

This topic has been closed to new replies.

About this Topic