Query for posts belonging to multiple categories
Query for posts belonging to multiple categories
Query for posts belonging to multiple categories
I tested this as a function. You can place it in your footer or functions.php theme file and call it in your themes footer section. See the comments for links to the functions used. function wpse_101774_footer() { // Start this part of footer on new line. echo “\n”; foreach ( array( 14, 19 ) as … Read more
Try get_terms( ‘product_cat’, ‘parent=” . get_queried_object_id() ) Update: Re-read your question, think I have a better idea: <ul class=”categories”> <?php wp_list_categories( array( “child_of’ => get_queried_object_id(), ‘taxonomy’ => ‘product_cat’, ‘title_li’ => ”, ‘depth’ => 2, ) ) ?> </ul>
Calling WP_Query three times isn’t too good for performance, as it will make three queries to the database. The way you’re currently approaching this seems like the proper (and fastest) way in may opinion. However, you should be calling $category_posts->rewind_posts() after each while-loop to reset WP_Query‘s loop to the first post. Furthermore, your current way … Read more
For the example you posted, the article is styled according to the css rule(s) for category-selling-and-advertising which is defined last (among the category-* classes) in the article’s class attribute. You need to intercept the functionality of post_class() to change the order these classes appear. The post_class filter will do the job for you: add_filter( ‘post_class’, … Read more
The child ul comes with the class “children”, so you can use this to target your css. ul.children li { } Even without that, though, you could just use the hierarchy of lists to target.. ul#catList ul li { } would target any li within a ul, within the #catList ID.
Try to use orderby name and order asc and desc to achieve category order $categories = get_categories( array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ) ); foreach( $categories as $category ) { echo $category_names = $category[1]->name; } // echo wp_json_encode($category_names);
Add a check wherever you’re displaying the title: //Anything greater than 0 means the category has parents, 0 means no parent, child category if($category->category_parent > 0){ echo $category[0]->cat_name; } This should help.
Simplest solution would be: <li><ul> <?php wp_list_pages(‘title_li=&child_of=”.$post->ID.”‘); ?> </ul></li> Use this code for more flexibility: <?php if ( is_page() ) { ?> <?php if($post->post_parent) $children = wp_list_pages(‘title_li=&child_of=”.$post->post_parent.”&echo=0’); else $children = wp_list_pages(‘title_li=&child_of=”.$post->ID.”&echo=0’); if ($children) { ?> <li> <h2> <?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?> </h2> <ul> <?php echo $children; ?> </ul> </li> <?php } } … Read more
Nice to see Liverpool at the top there! I’d go about this using a page template. Given that as far as I’m aware we only know the page names I’ll add it in that way. The process is this: Loop through top level pages Collect child pages as array Loop through child pages Loop through … Read more