• Resolved fooentes

    (@fooentes)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • This should do the trick:

    $sep = '&raquo;';
    $parents = get_category_parents( $cat, TRUE, $sep );
    $parents = explode( $sep, trim( $parents, $sep ) );
    $parents = array_reverse( $parents );
    $parents = implode( " $sep ", $parents );
    print $parents;
    Thread Starter fooentes

    (@fooentes)

    thanks!

    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 = " &lsaquo; ";
    $parents = get_category_parents( $cat, FALSE, $sep );
    $parents = trim($parents);
    $parents = explode($sep,$parents);
    $parents = array_reverse($parents);
    $parents = implode(" ",$parents );
    print $parents . " &lsaquo; ";
    }

    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

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