Style post archive blog preview based on category

This sounds like something that should go to the The Loop – you want this class per post, not for the whole <body>, right? Roughly archive.php (or index.php, or category-*.php) should look like this: while (have_posts()) { the_post(); $add_class = array(); if (in_category(‘new’)) { // inside the loop, don’t need $post->ID $add_class[] = ‘new’; if … Read more

how to get only grandchild category from a child category

One way you could do it is to make another get_categories inside the foreach ( $categories as $category ) Example code //preparing an array to hold later info $grandchildren_ids = []; //getting the child categories of parent 72 $args = array( ‘orderby’ => ‘name’, ‘parent’ => 72, ‘taxonomy’ => ‘category’, ‘hide_empty’ => 0 ); $categories … Read more

Hide a category/posts from the homepage in wp

Have you tried Ultimate Category Excluder plugin? You can use it to exclude categories very easily. You just need to select the categories that you want to remove. It can be very useful, as you are not comfortable with coding. Also, you can try using the following codes: function exclude_category_home( $query ) {if ( $query->is_home … Read more