Articles of categories

Counting number of posts in a category and its sub categories and displaying result using shortcode

I am trying to create a shortcode to display the posts count in a category. I have successfully done this using this code: // Add Shortcode to show posts count inside a category function add_count_of_posts_in_category() { $term = get_term( 7, ‘category’ ); $count = $term->count; echo $count; } add_shortcode( ‘show-posts-count’, ‘add_count_of_posts_in_category’ ); However, this means […]

Different template for posts of all subcategories of category

I want to use different template for posts of all subcategory of one category. Below is the Code I am using : add_filter( ‘single_template’, ‘get_custom_cat_template’ ) ; function get_custom_cat_template( $single_template ) { global $post; if ( is_category( ‘blog’ ) || in_category( ‘blog’ ) ) { $single_template = dirname( __FILE__ ) . ‘/single-blog.php’; } return $single_template; […]

Sorting posts by season

What would be the best way to go about creating something like this ( in WordPress? This is a calendar, with posts (containing the event date and event description), separated by year. A thought doing something like this, but I do not know, if this is a good solution, or if it is possible: Creating […]

How to link 2 categories (Sync)

I want that whenever a user post something in category “Foo”, the same content must be duplicated to the category “Bar” automatically. Is there such a plugin that automate the process? Or some PHP snippet? I have many categories. Those categories are not the normal WordPress categories, they are custom, for a specific theme, like […]

wp_query display posts from same category of the post

On my post page I am trying to display list of other posts from the same category of the original post. So far I got this and this does not seem to work: <?php $args = array( ‘post_type’ => ‘article’, ‘posts_per_page’ => 5, ‘post__not_in’ => array( get_the_ID() ), ‘category’ => array( get_the_category() ), ‘meta_query’ => […]

Remove child products from woocommerce category page

I have a taxonomy template that display products from both parent and child terms, how can I show only the products belonging to the parent terms? I’m trying to modify somehow this part of code: <?php woocommerce_product_subcategories(); ?> <?php while ( have_posts() ) : the_post(); ?> <?php wc_get_template_part( ‘content’, ‘product’ ); ?> <?php endwhile; // […]

Detect whether a page is a product subcategory page?

How can I detect whether current page is a product sub category page? I’ve tried with the following but it will always print out “NO” function is_subcategory($category = null) { if (is_category()) { if (null != $category){ $cat = get_category($category); }else{ $cat = get_category(get_query_var(‘cat’),false); } if ($cat->parent == 0 ){ return false; }else{ return true; […]

Is it possible to have WordPress not recognize category URLs?

I don’t want to support Categories in my WordPress site. I know I can have an empty category.php page to cater for users using a URL to directly query the default Category (/category/Uncategorized), but I was wondering if there’s a way to shut off WordPress’s recognition of the category URLs, so that any attempt to […]

Overriding default calendar to show posts from a category

I’m trying to modify the default WP calendar (get_calendar()) so that it shows posts from a specific category and then use that as a shortcode. Here’s what I’ve done: Copied across the get_calendar() function from the core (from wp-includes) into my child theme’s functions.php file. In order to make it an ‘independent’ calendar, I changed […]

get_query_var() and permalinks

I have a permalink structure that looks like this, %category%/%postname% I have a category.php template coded up and and trying to pull of the post of a certain category, so for example my URL may look like this, /category/category1 I want all posts that are in category1 to be return however, when using the following […]