• Resolved gillsans

    (@gillsans)


    Is there anyway to reorder which category displays first?

    Using the get_the_category?

    <?php
    $category = get_the_category();
    echo $category[0]->cat_name;
    ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter gillsans

    (@gillsans)

    Anyone know how to edit the order that categories are displayed?

    MichaelH

    (@michaelh)

    Not that I have an answer, but rather a question.

    In what order do you want to display the categories for a given post?

    Thread Starter gillsans

    (@gillsans)

    Good Questions.

    Right now they display alphabetically, it would be nice if there was a way to sort then by first category added when the post was created.

    The reason being is I’m calling the first category to display at the topic of the blog post but this may not display my first choice but the alphabetical first.

    Hope that helps. Clear as mud 🙂

    MichaelH

    (@michaelh)

    Painfully clear 😉 Might try something like this:

    <?php
    $args=array('orderby' => 'none');
    $terms = wp_get_post_terms( $post->ID , 'category', $args);
    foreach($terms as $term) {
      echo '<a href="' . esc_attr(get_term_link($term, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
    }
    ?>
    Thread Starter gillsans

    (@gillsans)

    That displays all of the categories. I only want to display the first category selected when creating the post.

    MichaelH

    (@michaelh)

    Then put a counter in that foreach that only iterates once.

    Thread Starter gillsans

    (@gillsans)

    will do. thanks 🙂

    Hello Michael,

    Your solution works great. Do you think there is a chance to display only the last category => grandchild with your solution ?

    Hello to all, 😉

    Hello Michael,

    Your solution works great. Do you think there is a chance to display only the last category => grandchild with your solution ?

    I’m interested too… anyone have a solution?

    hey Michael,

    is it possible to seperate the categories with a comma or any symbol in your solution?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘get_the_category order’ is closed to new replies.