New answers tagged

0

I have very 4 lines solutions, It shows category and sub-categories and their posts count. $cats = get_terms('category'); foreach ($cats as $cat) { echo $cat->name . "<br>" . "(" . $cat->count . ")"; }


1

Feed links have to use the category slug (not the name) ("Blog-Artikel" --> "blogpost" in the case of the site in question) Feed links have to conform with the localization of the page offering the feed (i.e. "category" --> "kategorie" for a WP site with a Germain domain. Funny enough, the WP site language of ...


0

This is an advanced example for developers. It supports custom post types and custom taxonomies, including matches by multiple taxonomies. // $post pointing to a WP_Post instance of the current post. $query = new WP_Query( [ 'post_type' => $relatedPostType, 'posts_per_page' => 6, 'tax_query' => ...


1

put this on your functions.php and then call the function in whatever page desired. this code is prepare to use css. if (! function_exists('menu_categories')) { function menu_categories(){ $cat_args = array( 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => true); $cats = get_terms( 'product_cat', $cat_args ); ?> <h1>...


0

This one works for me. The answer found in this link on the second last post/comment: https://wordpress.org/support/topic/wp-nav-menu-dissapears-in-category-pages-1/?replies=15#post-1859168 Just need to add this on the theme's function.php file add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if(is_category() || is_tag()) {...


0

If you are using Gutenberg Block Editor on WordPress, you can try the Gutentor plugin and use Advanced Post (Type) Block. You can check Advanced Post (Type) Block demo. You can Filter the Post by Category ( any post type with their taxonomy terms) and also add other options like pagination, navigation and load more button.


0

So I wonder why don't you just set the category title via the admin page, e.g. for the one having the slug alphabetical, you could set All Characters as a static title for the category? That way, you wouldn't need to hook on get_the_archive_title.. But anyway, here is one way of how can you reduce those (26) elseif into just one: (using regular expression) ...


0

Please add this code in functions.php to remove the "category" text from permalink. function remove_category( $string, $type ) { if ( $type != 'single' && $type == 'category' && ( strpos( $string, 'category' ) !== false ) ){ $url_without_category = str_replace( "/category/", "/", $string ); ...


0

You can use below code to append the string: <?php $category = get_the_category(); $related_blog .= '<div><a href="'. get_category_link($category[0]->cat_ID). '">'. $category[0]->cat_name.' </a></div>'; ?>


0

Okay so it's going to say the categories number for each post when you fetch posts. Then you can just filter by the category number like this: const wpdata = await fetch(`http://example.com/wp-json/wp/v2/posts`); const jsonresp = await wpdata.json() const particularcategoryposts = jsonresp.filter(function(item){ return item.categories == "4"; ...


2

Try: $mycategory = array(23, 33, 37); if( is_category( $mycategory ) ) { echo 'yes'; } else { echo 'no'; } is_category returns true if there are any matches. You could try this: ... $term = get_term_by( 'id', $child, $taxonomy_name); if ( is_category( $term->term_id ) ) { $mycategory[] = $term->term_id; }


Top 50 recent answers are included