Forums

[resolved] Category order (3 posts)

  1. mrspabs
    Member
    Posted 4 months ago #

    I am trying to build a category breadcrumb. i have this code

    <?php
    $category = get_the_category(); echo $category[1]->cat_name; ?>/<?php
    $category = get_the_category(); echo $category[0]->cat_name; ?>/<?php echo $post->post_name; ?>

    Any my categories are like this

    Long Island
    - Uniondale
    - Happauge

    The weird thing is, sometimes the categories print like this

    Long Island / Happauge / Post Name
    Uniondale / Long Island / Post Name

    I tried unassigning and reassigning the category, but that doesn't seem to work.

    So long story short, how can i change the order of the array of categories assigned to a post?

  2. YouON
    Member
    Posted 4 months ago #

    order by id?

  3. mrspabs
    Member
    Posted 4 months ago #

    Here is an answer to my own question :)

    This code will output the categories in the correct order.
    <?php echo get_category_parents($cat, FALSE, '/'); ?>

    if you do this, it will do it with links
    <?php echo get_category_parents($cat, TRUE, '/'); ?>

Reply

You must log in to post.

About this Topic

Tags