Y
Y
ygen2016-02-11 23:38:40
Taxonomy
ygen, 2016-02-11 23:38:40

How to display subcategories from current category and 5 latest entries?

I can't find a solution at all. Tell me please.
The category has 10 subcategories. How to display them in this format in the template?
Subcategory1
photo photo2 ... 5
post1 post2 .... 5
Subcategory2
photo photo2 ... 5
post1 post2 .... 5
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Belikov, 2016-02-12
@ygen

Perhaps something like this:

// основные категории
$categories = get_categories( array(
    'parent'  => 0
) );
foreach ( $categories as $category ) {
    // подкатегории
    $sub_categories = get_categories( array(
        'parent'  => $category->term_id
    ) );
    foreach ( $sub_categories as $sub_category ) {
        // записи
        $posts = get_posts( array( 
            'category' => $sub_category->term_id,
            'posts_per_page' => 5,
            'orderby' => 'date',
        ) );
        foreach ( $posts as $post ) {
            // вывод поста и фото
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question