WordPress.org

Ready to get started?Download WordPress

Forums

the_category doesn't list all of the categories (6 posts)

  1. davaobase
    Member
    Posted 3 years ago #

    I've been scouring search engines and help blogs for hours, but I can't get to a solution. :(

    In my single post code (single.php), I use the following snippet to display all categories where the single / individual post belongs to:

    Filed under <?php the_category(', ') ?>

    Some of my posts belong to two categories, but the two categories don't appear on the portion where the above code was placed.

    Example page: http://www.pinoyengineers.com/2010/08/resolution-no-2004-211/

    This post is filed under two categories: "Instruction to examinees" and "Laws". Weird as it may seem, look at the end of the post to see the categories where it is placed:

    Filed under Laws (but the link points to "Instruction to examinees")

    I want this part to appear as:

    Filed under Instruction to examinees, Laws

    HELP!

  2. chinmoy
    Member
    Posted 3 years ago #

    use this once get_the_category_list( ', ' )

  3. Kapil Chugh
    Member
    Posted 3 years ago #

    In WordPress 3.0 they are using this method to show categories and tags.

    $tag_list = get_the_tag_list( '', ', ' );
    	if ( $tag_list ) {
    		$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
    	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
    		$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
    	}
    printf(
    		$posted_in,
    		get_the_category_list( ', ' ),
    		$tag_list,
    		get_permalink(),
    		the_title_attribute( 'echo=0' )
    	);
  4. davaobase
    Member
    Posted 3 years ago #

    Thanks for the replies, chinmoy29 and Kapil Chugh. I tried both of your suggestions as such:

    1. I used echo get_the_category_list(', ') to display the category list, but it still shows only one category.

    2. Kapil, I used your exact code, which also made use of the get_the_category_list function. Still, only one category is showing.

    Any other suggestions?

  5. davaobase
    Member
    Posted 3 years ago #

    GOT IT!

    I used the following code to list all categories where the specific post is filed under, including the links to the categories:

    <?php echo get_the_term_list( $post->ID, 'category', '', ', ', '' ); ?>

    I just treated "category" as a taxonomy. :)

  6. Kapil Chugh
    Member
    Posted 3 years ago #

    Thx for sharing it.

Topic Closed

This topic has been closed to new replies.

About this Topic