WordPress.org

Forums

category name help (3 posts)

  1. croakingtoad
    Member
    Posted 6 years ago #

    In the code example below, I have a line -

    wp_list_pages("title_li=".$post->post_parent." etc...

    The var $post->post_parent returns a category number. How do I get it to return the category name?

    Thanks!

    <?php
    			if($post->post_parent) {
    				$children = wp_list_pages("title_li=".$post->post_parent."&child_of=".$post->post_parent."&echo=0");
    			} else {
    				$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    			}
    			if ($children) { ?>
    				$cat = $post->post_parent;
    				<ul>
    				<?php echo $children; ?>
    				</ul>
    			<?php } ?>
  2. croakingtoad
    Member
    Posted 6 years ago #

    bump

  3. iridiax
    Member
    Posted 6 years ago #

    Your code is for pages not categories, and the page ID number is needed for the child_of= in wp_list_pages. The name would not work here.

    This is for listing categories:

    http://codex.wordpress.org/Template_Tags/wp_list_categories

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.