WordPress.org

Ready to get started?Download WordPress

Forums

List of category by get_the_category (2 posts)

  1. noumen
    Member
    Posted 4 years ago #

    Hi,

    Sorry for my english, at first!

    I have, problem with code it goes like this:

    <?php if ( is_category('8') ) {
    	       	foreach (get_the_category() as $category); ?>
           	<div>
    	       	<h2><?php echo $category->cat_name; ?></h2>
        	   	<p><?php echo $category->category_description; ?></p>
           	</div>

    What I need is to display on page list of sub-sub-categories. On my blog there is category "NUMBERS" under this category there is category NUMBER 1, under this sub-cat, there is sub-sub-category NUMBER 1-1, NUMBER 2-2, NUMBER 3-3

    NUMBERS - (0 pots)
    - NUMBER 1 - (0 pots)
    -- NUMBER 1-1 - (10 pots)
    -- NUMBER 2-2 - (10 pots)
    -- NUMBER 3-3 - (10 pots)

    On each ssub-sub-czategor i have about 10 post, when i click on NUMBERS category (link) i get list of 30 posts (chronlogical but ungroup) this list is generate by THE LOOP.

    What I need is to get a lists of sub-sub-categories in any order, but with:

    name, description, image.

    When i use code above i get only first sub-sub-category (NUMBER 1-1) witch is last added cat (with posts).

    I can't use wp_category_list becouse there is no description, and I can't put name, descriprion or img into specified div tags witch i need to show.

    To be more clear:

    I click on category NUMBERS -> on main page I need to display list of sub-sub-categories with name, description and image, then i click on sub-sub-cat and I get posts (posted uder this sub-sub-cat).

    <?php if ( is_category('8') ) 
    
    { 
    
    //show me sub-sub-cat from CATEGORY 8
    
    <?php } else { ?> //if I don't cilick on category 8 show me posts from category I've cliked
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    //showing posts

    Any ideas?

  2. stvwlf
    Member
    Posted 4 years ago #

    Rather than get_the_category, look at get_categories()
    http://codex.wordpress.org/Function_Reference/get_categories

    This uses parameters like wp_list_categories but creates an array of the category results. You can process the array in a loop and add in the description and images you need in the loop.

Topic Closed

This topic has been closed to new replies.

About this Topic