0

I want to show different style for parent and child category how can i do it? if i browse parent category then show a style and when browse child category then show different style And how can i show only parent category name and 3 post from this category like

1.parent category name1

……3post of this category……

2.parent category name 2

……3post of this category……

2
$categories = get_categories( array(
    'parent' => 0,
) );

foreach ( $categories as $category ) {
    echo $category->name;
    $posts = get_posts( array(
        'category_name'  => $category->slug,
        'posts_per_page' => 3,
    ) );
    foreach ( $posts as $item ) {
        echo get_the_title( $item->ID );
    }
}

Something like this print wich you need. But it is very simple example.

  • I want for parent category only – Arpan Feb 7 '18 at 14:12
  • Updated get_categories params. This code will show just parent categories. – Maxim Sarandi Feb 7 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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