• Resolved ceslava

    (@ceslava)


    When updated to WP 2.5 the function get_category_link($cat) when use in single it doesn′t work anymore. It returns the category base which means is like this post it doesn′t belong to any category, returns ID 0.

    Thank you in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ceslava

    (@ceslava)

    I resolved it by creating a new function based on the_category which works perfectly in a single.

    This is the only way I could extract the category link in a single

    Hi ceslava,
    I have the same problem.
    Please can you post that function here ?
    Thanks

    Thread Starter ceslava

    (@ceslava)

    Sure, zeroo,

    function get_categoria_post($separator = '', $parents='') {
    	global $wp_rewrite;
    	$categories = get_the_category();
    	if (empty($categories))
    		return apply_filters('the_category', __('Uncategorized'), $separator, $parents);
    
    	$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
    
    	$thelist = '';
    	if ( '' == $separator ) {
    		$thelist .= '';
    		foreach ( $categories as $category ) {
    			$thelist .= "";
    			switch ( strtolower($parents) ) {
    				case 'multiple':
    					if ($category->parent)
    						$thelist .= get_category_parents($category->parent, TRUE);
    					$thelist .=  get_category_link($category->term_id);
    					break;
    				case 'single':
    					$thelist .= get_category_link($category->term_id);
    					if ($category->parent)
    						$thelist .= get_category_parents($category->parent, FALSE);
    					$thelist .= $category->name.'</a></li>';
    					break;
    				case '':
    				default:
    					$thelist .= get_category_link($category->term_id);
    			}
    		}
    		$thelist .= '';
    	} else {
    		$i = 0;
    		foreach ( $categories as $category ) {
    			if ( 0 < $i )
    				$thelist .= $separator . ' ';
    			switch ( strtolower($parents) ) {
    				case 'multiple':
    					if ( $category->parent )
    						$thelist .= get_category_parents($category->parent, TRUE);
    					$thelist .= get_category_link($category->term_id);
    					break;
    				case 'single':
    					$thelist .= get_category_link($category->term_id);
    					if ( $category->parent )
    						$thelist .= get_category_parents($category->parent, FALSE);
    					$thelist .= "$category->cat_name</a>";
    					break;
    				case '':
    				default:
    					$thelist .=get_category_link($category->term_id);
    			}
    			++$i;
    		}
    	}
    	return apply_filters('the_category', $thelist, $separator, $parents);
    }

    Check it out in justtellmewhy.com

    <a href="<?php echo get_option('home'); ?>">Home</a>&nbsp;&rsaquo;&nbsp;&nbsp;<?php the_category('&nbsp;&rsaquo;&nbsp;&nbsp;', 'multiple' ); ?>&nbsp;&rsaquo;&nbsp;&nbsp;<?php the_title(); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_category_link in single’ is closed to new replies.