fooentes
Member
Posted 1 year ago #
Hi there, i'm having some problems with:
<?php echo(get_category_parents($cat, TRUE, ' » ')); ?>
it returns: INTERNET » SOCIAL MEDIA » TWITTER » MARKETING
I'd like to output this:
MARKETING » TWITTER » SOCIAL » MEDIA » INTERNET
is there any way i can do that?
thx
This should do the trick:
$sep = '»';
$parents = get_category_parents( $cat, TRUE, $sep );
$parents = explode( $sep, trim( $parents, $sep ) );
$parents = array_reverse( $parents );
$parents = implode( " $sep ", $parents );
print $parents;
fooentes
Member
Posted 1 year ago #
smeknamn
Member
Posted 1 year ago #
Some categories lost letters in the end of the word when using Michael Fields trick. I changed the code a little bit and now it seems to work. I don't know what this bug came from. It works when I use:
if(is_archive()){
$sep = " ‹ ";
$parents = get_category_parents( $cat, FALSE, $sep );
$parents = trim($parents);
$parents = explode($sep,$parents);
$parents = array_reverse($parents);
$parents = implode(" ",$parents );
print $parents . " ‹ ";
}
The problem seems to occur when I using the explode() and trim() at the same row...
@smeknamn great catch! Sorry for the oversight. Sometimes I forget what the second parameter passed to trim() actually does. Instead of removing the string trim() removes the individual characters as shown in the Hello World example in the docs: http://php.net/manual/en/function.trim.php