SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Listing WordPress categories

    Hey everyone, I've got this in my WordPress template at the bottom of single posts:

    Code:
    If you enjoyed this post, read more like it in <?php the_category(' &amp;'); ?>
    The &amp is placed after each category. So a post listed in red and blue categories would show:

    ...read more like it in red & blue.

    The problem:

    If I archive a post in 3 categories, it will show:

    ...read more like it in red & blue & green.

    I'd like it to instead show:

    ...read more like it in red, blue & green. While posts with two categories should show red & blue.

    And, only if possible: red, blue, green & black.

    Anyone know how to work this?

    Thanks in advance.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    cat links

    You miight be able to get a "cleaner" (ie. plugin ref) answer if you move this to the blogging forum. But you could save a backup of the category-templates.php file and hack the get_the_category_list function.
    PHP Code:
            $i 0;
            foreach ( 
    $categories as $category ) {
                if ( 
    $i )
                    
    $thelist .= $separator ' ';
                switch ( 
    strtolower($parents) ) {
                    case 
    'multiple':
                        if ( 
    $category->category_parent )
                            
    $thelist .= get_category_parents($category->category_parentTRUE);
                        
    $thelist .= '<a href="' get_category_link($category->cat_ID) . '" title="' sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>';
                        break; 
    just find the length of the categories array and put in a conditional so commas are the separator except for the last ampersand.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for your help, Mittineague, but would it be possible for you to show me the exact change I need to make? Sorry, I'm a PHP noob.

    I've been reading the documentation at PHP.net but I'm not that far yet.

    Thanks,
    Chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •