The conditional you use to output get_template_part('content', 'none');
is only triggered if there is no post in the main loop, for example, when a category has no posts in it:
if (have_posts()){
while(have_posts()) {
the_post();
// If the category has a post and we are on a category page, then show the posts
get_template_part('content', 'archive');
}
} else {
//If the category has no posts, display a message that no post exists
get_template_part('content', 'none');
}
But this only happens when you visit www.example.com/category/some-cat/
, and the /some-cat/
is actually an existing category slug. If you try to access a page that doesn’t exist, the 404.php
template will be used instead.
Related Posts:
- Loading partial templates with AJAX/PJAX
- Templates & CSS – Proper Programming Practice?
- index.php template is used instead of blog page
- Load template file without a post type
- How to apply a custom template for posts by default?
- Unable to include a template
- Turning on the 404 page on localhost
- What should I put on my index.php?
- get_search_link() redirects to 404 template page
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- Why are 404s not triggering my 404.php template?
- Having trouble with Template hierarchy. I Need to create a set of pages that drill down from states to specific locations
- Custom templates vs page-slug
- Understanding the Template hierarchy
- How does WordPress choose archive type template?
- Use one template only for custom post type archives?
- Taxonomy term page going to 404
- get_month_link uses what wordpress template?
- Differentiation between index.php and page.php
- Single-page.php template file name not shown
- Can I assign a Folder for Post Formats, without it affecting WordPress’ fallback/hierarchical system?
- How to display custom post type?
- Assigning custom page templates to a static blog page
- Archive-custome_post.php template not working
- /wp-admin/post.php shows 404 template on submit
- Organize template parts and page templates in folders in regards of template hierarchy
- Help Understanding Template Hierarchy
- User role templates
- Assign template to custom page type?
- BuddyPress : how can I call the template WordPress would have chosen (template hierarchy)?
- Display a custom 404 page without a redirect
- How can I make custom page templates work on child theme?
- Which template(s) to override to use a different sidebar for blog, single posts, categories, blog archive?
- Single Post Templates Doubt
- Page Templates Used in Custom Post Type
- Show a custom template, no matter the page being viewed, if the user is not logged in
- Is this the best way to complete disable category archive pages?
- wp e-commerce single-product template giving 404
- Unload templates; disable parent Template Parts using only “theme.json”
- How to use Class
in Java? - Get name of the current template file
- How do you find out which template page is serving the current page?
- How to change the default registration email ? (plugin and/or non-plugin)
- How do I get the size of an attachment file?
- Is there any way to use get_template_part() with folders?
- How to create custom 401, 403 and 500 error pages?
- single-{$post_type}-{slug}.php for custom post types
- Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
- How can i change email template for new user
- Any advantage to using get_header() over include(‘header.php’)?
- Enable page templates. How?
- Is it possible to override the result of get_template_part()?
- Use [embed] filter in template files
- What’s the purpose of the paged.php file?
- How do you access the Product Short Description in a WooCommerce email template? [closed]
- Prevent comments_template() to load comments.php
- Is there a way to list all used/unused WP templates?
- Page editor missing Templates drop down
- Print WordPress template filename(s) for debugging
- How to force TinyMCE in WordPress to replace newlines with tags and not with
- How to find the posts page (home page) programatically
- WooCommerce: Change template for single product page
- View WordPress page template usage (or unused)
- How to edit contents of dynamic_sidebar()?
- How to check if a shortcode exists?
- Where is get_header(‘shop’) file in Woocommerce templates
- Custom templates folder
- What is the link to my default “archive” page?
- Custom Post Types 404 Issue
- How to get slug of current category in taxonomy template?
- How to show a under construction page for a domain but still be able to work on index.php?
- Change the name of the ‘Default Template’
- Customizing get_the_excerpt() to specific length and “Read More” output.
- How to Rename a Template File?
- Template for specific post of custom post type
- get page templates
- Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing
- Using WordPress templating for HTML emails
- Is it possible to manipulate the list of page templates?
- WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK
- How do you check if a WordPress template file exist?
- Multiple Single Post templates
- Taxonomy Templates… by hierarchical level?
- Load entire NextGEN gallery from single thumbnail?
- I put my blog on a subpage, how do I get page title?
- A special single page templates for posts under a category and all its child category
- Different wordpress 404 template for different post type [duplicate]
- Custom reset password template after forgot password request
- Outputting Canonical Resource URLs Across a Multisite Network?
- Gravity Forms Custom Templates [closed]
- Child Theme: how to override variables?
- How do I get the URL of a specific size featured image?
- Where to store some per-template preferences?
- add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
- stop blog page from using index.php?
- How can I modify the default reset (lost) password email text?
- Different templates for parent and children categories/taxonomies
- How to create tag.php
- Template files missing after moving site
- How do I override template-tags.php in twentyseventeen theme