It looks like the single quotes are giving you problems.
Replace:
get_template_part( 'templates', '$childcat->slug' );
with:
get_template_part( 'templates', $childcat->slug );
Note that double quoted strings in PHP can parse variables, not single quotes.
Also check out the curly syntax in the PHP docs in the variable parsing section.
Related Posts:
- What does the token %1$s in WordPress represent [closed]
- retrieve thumbnail from post ID of best selling product in category
- Custom HTML structure in wp_list_categories
- Display all posts in current category
- How to Populate the list of custom post type categories
- Php string not working in WordPress Functions.php [duplicate]
- User Defined order on get_categories?
- get_template_part not working with ajax
- How can I set custom order use this function
- Categories Template Assistance
- Error: array_map(): Argument #2
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- Check if Product is in a Specific Category in Functions.php
- Display all categories including sub categories
- Custom category code not showing all posts
- How to use transient in this code for related post?
- Swapping wp_dropdown_categories function with wp_category_checklist
- how could I load a different template part by page
- What is an equivalent of single_cat_title for getting the slug of the category?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Move category description below post list in blog
- Applying A Category to Existing Posts Where Page Title Matches Regex
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Display category name only once inside loop
- get_template_part for specific page
- Dilemma of Populating all the categories in a drop down list
- Display most popular posts of category
- JSON REST API WordPress only showing first 10 categories
- get taxonomy thumbnail and use it as a variable in code
- Echo a shortcode div after every 3 posts
- Get all categories post is not in
- Get latest post from all categories except one
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Only show size attributes in product box woocommerce when available
- Custom post type category not displaying category ID
- Argument for if term-> have child?
- How to get current post category details inside “loop”?
- Post not populating for custom post type based on category selection
- Select through customizer the template part to be viewed
- Removing sidebar on category pages
- get_template_part function and add images
- Showing Subcategory Name/Link Instead of Parent Category
- WordPress custom taxonomy
- go to home page when i select default in select-box
- Finding and removing duplicates within WP Arrays
- Compare current post Category in select menu
- Get the list of post categories
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- Woocommerce. Get a list of products in the current category on the archive page and product page
- Wrong Number of Products When Hiding Subcategory Products From Showing In Parent Category
- How to show categories and date on posts
- How do I edit the terms output args or array data?
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Allow two posts (from different categories) to have the same slug
- Get main parent category for post (WordPress/Advanced Custom Fields)
- Display Visual Composer shortcode if a post belongs in specific categories
- Using the get_template_part method within an mu-plugin not possible?
- Category Page Displaying all Pages
- How to enable HTML tags in category description without breaking the category page
- Trying to show the category of a post in the post display
- Link to index.php from home.php?
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Hide a specific category title from displaying on site
- Return to the beginning of the results of a for loop
- Exclude category and post from loop in custom category.php
- Admin backend, show post from a category and exclude the posts from subcategories
- Populate Posts based on category selected using AJAX that means without page refresh
- random woocommerce categories are not showing when count enabled?
- Exclude a category slug on pagination
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- How to Retrieve All Category Images on Front-End
- How to use get_template_part always relatively to the file I’m using it in?
- Short code into PHP
- Code works on page-example.php by not category-example.php
- Need Quick Help With Product Category Page
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- Removing get_template_part in child theme
- Search in particular category in wordpress
- Is this correct get_template_part() in WordPress?
- Is there a way to randomize and connect a background and header image?
- wp_get_archive for category returning different URLs on different but similar sites
- Error trying import one category on page
- dynamically filter by category via sub-menu
- Get unique post in parent category
- Code that displays images – images get shown multiple times
- Incomplete term slugs output from a foreach loop with get_the_terms
- Display post of specific category on page
- Displaying categories
- Product Category Page in Full Width
- How to insert the first letter in uppercase [closed]
- Display all categories (with link) of custom post type – WordPress
- How to limit number of posts in the certain category and exclude the oldest post automatically
- child category under correct parent
- Display featured posts first, then display all others within a specific category in WordPress
- Can’t assign menu parent id or menu item breaks
- Prevent publishing of uncategorized posts