• WORDPRESS VERSION: 2.7.1

    Hi,

    I am trying to get the name of child category whose article get’s printed as the latest one from the Root category. I have a hierarchy of categories in my site e.g.

    * ROOT
    |- child 1
    |- child 2
    |- child 3

    With the following code, WP prints out “Root” category name with an article from one of the children depending which is the latest one:

    <?php query_posts("showposts=1&cat=$category");
    	    $wp_query->is_category = false;
    		$wp_query->is_archive = false;
    		$wp_query->is_home = true;
    		 ?>
          <h3><a href="<?php echo get_category_link($category);?>">
            <?php
    	// name of each category gets printed
    	  single_cat_title(); ?>
            </a></h3>
          <?php while (have_posts()) : the_post(); ?>
          <?php

    The function single_cat_title(); prints out the Root category name and I would like to replace it with the name of the child category.

    Thanks for your help!

    Omer

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try something like this:

    <?php wp_list_categories(‘child_of=8’); ?>

    Thread Starter okhalid

    (@okhalid)

    This will give me the children of the category 8 right?

    What I want is that once a post is received belonging to child1, then to get it’s category name as child 1 rather then displaying “root” category name!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get children categories name’ is closed to new replies.