Forums

Setting order when displaying child categories in post meta (1 post)

  1. dianat
    Member
    Posted 3 months ago #

    I need to be able to display multiple child categories with links in post meta, like the following, setting the order in which it's displayed by the parent category.

    Color: Red
    Shape: Circle
    etc.

    The following code pulls the info I want, yet returns the content in alpha order by child rather than parent.

    <span class="cat-links">
    	<?php
    	foreach((get_the_category()) as $childcat) {
    	if (cat_is_ancestor_of(3, $childcat)) {
    	echo 'Color: '. '<a href="'.get_category_link($childcat->cat_ID).'">';
     echo $childcat->cat_name . '</a>';
    	}
    	if (cat_is_ancestor_of(10, $childcat)) {
    	echo 'Shape: '. '<a href="'.get_category_link($childcat->cat_ID).'">';
     echo $childcat->cat_name . '</a>';
    	}
    	}
    	?>
    </span>
    <?php endif; // End if categories ?>

    One post ends "Color: blue | Shape: circle" and another ends "Shape: circle | Color: red." Each post needs the category meta displayed in a consistent order according to parent.

    Any ideas?

Reply

You must log in to post.

About this Topic