• Resolved hafman

    (@hafman)


    Still not easily possible?

    I’m running out of patients on this. Does anyone know of a simple way to highlight multiple categories in a list on single.php?

    My current code only brings up a single category, it uses wp_list_categories, intended for archive pages i know. Strange that there is not yet a function for the single post template. Or is there?

    <?php $catsy = get_the_category();
    $myCat = $catsy[0]->cat_ID;
    wp_list_categories(array(
    'title_li' => '',
    //ONE AT A TIME PLEASE 0_0
    'current_category' => $myCat ?>

    It shouldn’t have to be a massive hack.
    Here’s one of the posts with only one category showing:
    http://www.purkiss-archive.eu/hambling-maggi/
    There should be two.

Viewing 1 replies (of 1 total)
  • Thread Starter hafman

    (@hafman)

    Behold, the solution…

    <?php
    $cat_args = array(
      'orderby' => 'name',
      'order' => 'ASC'
    );
    $categories = get_categories($cat_args);
    foreach($categories as $category) {
    	if ( in_category( $category->term_id ) ) {
    		?>
    		<li class="cat-item current-cat cat-item-<?php echo $category->term_id; ?>"><a title="View all posts filed under <?php echo $category->name; ?>" href="<?php echo get_category_link( $category->term_id ); ?>"><?php echo $category->name; ?></a>
    		</li>
    		<?php
    	} else {
    		?>
    		<li class="cat-item cat-item-<?php echo $category->term_id; ?>"><a title="View all posts filed under <?php echo $category->name; ?>" href="<?php echo get_category_link( $category->term_id ); ?>"><?php echo $category->name; ?></a>
    		</li>
    		<?php
    	}
    }
    ?>

    Ronald Reagan face.

Viewing 1 replies (of 1 total)

The topic ‘multiple highlighted category list for single.php!’ is closed to new replies.