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? - Is there any way to use get_template_part() with folders?
- How to edit contents of dynamic_sidebar()?
- A special single page templates for posts under a category and all its child category
- Where to store some per-template preferences?
- How do I override template-tags.php in twentyseventeen theme
- roots child theme can’t override header.php
- Custom Post Type with Nested Taxonomy and Template Files
- Stream Video Player does not work with do_shortcode()?
- Which has more impact on site performance? Template overrides or hooks
- Advanced Custom Fields – display when specific template used?
- How To Create WooCommerce Custom Template For Specific Product?
- Have functions work outside the loop with 404 override
- Is there any way of viewing revision history on files in WordPress?
- Customize profile.php
- Change wp-signup.php Page Template
- Getting pages filtered by template assigned
- Use same page template for parent and child pages in a theme
- Markup is visible when I view sample data from my template
- if page is parent page redirect to first child with hook / polylang
- What are the main parts of a WordPress Template?
- Page template option missing
- Genesis – Adding custom hooks to display secondary navigation
- Force WordPress to NOT display the manual excerpt
- Custom Template page not loading get_header() correct?
- Easiest way to map content (in json) to the view (template)?
- Removing calls to noindex() and wp_no_robots()
- Query the database after get_header() has been included
- Does wp_mail work in frontend tempate file?
- Dynamically generated URL and Content page
- wordpress – modifying template to show more posts
- How to get all template files used for rendering a single post/page?
- How to insert “get_template_part()” based on Category ID?
- Home page not loading after editing header.php file
- How can I include ALL post types in the_post_navigation() links, not just current post type?
- Template includes
- Two different single.php depending on source page
- Attachment URL for an image is loading direct image file
- Fixing media query
- Set og:image programmatically in custom single post with external images
- Displaying all posts of a category in full view on one page using their single.php template
- Templating advice sub posts of a CTP
- why does not showing my custom post category list in any template?
- Locating the HTML piece of code in wordpress
- Custom Template doesn’t output result when set as homepage
- Theme keeps going to default files [closed]
- How can I show contents of a template part inside of another page?
- How to serve a amp template
- Single page applications with WordPress: routes and templates
- Inserting javascript file into theme template?
- Creating custom post-listing templates in twentyseventeen child theme
- Display different list of “Custom Templates” for each Custom Page Type
- Submit form to another template (ugly url)
- Using file outside of template hierarchy for Twitter sign in authentication
- List all pages using a specific template on a page
- Duplicated Template Does Not Load the Same as the Original Template File?
- Blog template PHP [closed]
- load_textdomain won’t load my .mo file
- why does blog page ignore template [closed]
- html blog template to wordpress template
- Dynamic header and footer template inclusion: footer script not included