Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

has anyone an ideea how can you do something like this:

So if the user is in a category, let's say Mainand this categories has some subcategories and I want to list them and also list the posts, something like this:

Sub category name 1

-POST 1

-POST 2

Sub category name 2

-POST 1

-POST 2

Sub category name 3

-POST 1

-POST 2

share|improve this question
add comment

1 Answer

I've found this piece of code and it works:

<?php get_header(); ?>
<div id="job-listings">
<?php
            $category = get_the_category();
            $theName = $category[0]->name;
            $theChild = $category[0]->cat_ID;
$subcats = get_categories('child_of=' . $theChild);
    foreach($subcats as $subcat) {
    echo '<h3>' . $subcat->cat_name . '</h3>';
    echo '<ul>';
    $subcat_posts = get_posts('cat=' . $subcat->cat_ID);
    foreach($subcat_posts as $subcat_post) {
        $postID = $subcat_post->ID;
    echo '<li>';
    echo '<a href="' . get_permalink($postID) . '">';
    echo get_the_title($postID);
    echo '</a></li>';
    }
    echo '</ul>';
    } ?>
 </div>
 <?php get_footer(); ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.