Support » Fixing WordPress » category issue (for coding) child-parent

  • Hi,
    I’m really stucked, as I am not very good at php..
    my problem is, I can not reach a parent category.
    here is the situtation,


    I write a post, and assign it to the -subCategory. well now, when I’m viewing the post, I can not echo the category MainCategory.

    I have searched all over the net, and read all the articles about breadcrumb in this site, but non of them works for me, I simply need to reach the category one up.

    when I view the post,

    foreach((get_the_category()) as $cat) {
    	$parent_category = $cat-> category_parent;

    so it gives me the parent category id, for instance, its 6
    it means that this is the subcategory of the category which ID is 6, how can I echo that category name ??

    I really dont get it, I searched and tried all the codes about category, but I can not find to way to reach the main category.

    one thing that I realise, if I write,
    <?php the_category('','multiple'); ?>
    shows, mainCategory/subCategory but I can not seperate them, it doesnt put space between words and also I want to put > between them.

    I’m going mad, trying to solve this problem for 5 days.

    please don’t say breadcrump plugins, cause none of them works for me.
    thanks in advance.

Viewing 1 replies (of 1 total)
  • try…
    $string = the_category(”,’multiple’);
    $string = split(‘/’, $string);
    echo $string[1]; // should echo subCategory
    echo $string[0]; // should echo mainCategory


Viewing 1 replies (of 1 total)
  • The topic ‘category issue (for coding) child-parent’ is closed to new replies.