WordPress.org

Ready to get started?Download WordPress

Forums

WP LIST CATS help please (9 posts)

  1. elyonline
    Member
    Posted 8 years ago #

    Hi there,

    I am looking at wp list cats: http://codex.wordpress.org/Template_Tags/wp_list_cats but I can't see anywhere that it will let me list all cats on an archive page like so:WordPress, Computers, Blogging, etc,

    Any ideas?

    Thanks

  2. lobsterman
    Member
    Posted 8 years ago #

    just use wp_list_cats()

  3. elyonline
    Member
    Posted 8 years ago #

    Nope, that lists the cats in a list < u l >, I want Computers, Blogging, etc, in a < p > tag.

    Thanks

  4. Kafkaesqui

    Posted 8 years ago #

    You'll need some custom code to get what you're after:

    <?php
    global $wpdb;
    $thecats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_count > 0 ORDER BY cat_name ASC");
    $eor = count($thecats) - 1;
    foreach($thecats as $thecat) :
    ?>
    <a href="<?php echo get_category_link($thecat->cat_ID); ?>" title="<?php echo wp_specialchars($thecat->category_description); ?>"><?php echo $thecat->cat_name; ?></a><?php if($thecats[$eor] != $thecat) echo ', '; ?>
    <?php endforeach; ?>

    This would take the place of <?php wp_list_cats(); ?> in your template.

  5. elyonline
    Member
    Posted 8 years ago #

    Hi Kafkaesqui,

    Many thanks for the code :)

    I am not sure if I am doing something wrong though as this just makes myarchive page white with no code on it.

    Thanks
    Karl

  6. Kafkaesqui

    Posted 8 years ago #

    I tested the code block above, but one can never be %100 sure...

    It's probably just bad placement of the code. Pop your template's source up here: http://pastebin.co.uk/ (click New Post at the top), and reply back with the link to it.

  7. elyonline
    Member
    Posted 8 years ago #

    Hi Kafkaesqui,

    Here is the link: http://pastebin.co.uk/603

    There is not much on this page so I guess it might conflict with smart archives: http://justinblanton.com/projects/smartarchives/ so that may be where the conflict is.

    If this is too much work I fully understand.

    Many thanks
    Karl

  8. Kafkaesqui

    Posted 8 years ago #

    This is working for me:

    http://pastebin.co.uk/605

    I guessed at the placement of my code. I assumed you would want the category listing just above the output from Smart Archives.

  9. elyonline
    Member
    Posted 8 years ago #

    Kafkaesqui,

    Thank you so much, I had been wanting to do this for so long and was sure there was a plugin. There wasn't, so you are a life saver.

    Thank you
    Karl

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.