Farhan, this should do it, add an else
to the if
statement:
$args = [
'post_type' => 'post',
'posts_per_page' => 1000
];
$q = new WP_Query($args);
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
?>
<p>The posts styling goes here</p>
<?php
}
// cleanup after the query
wp_reset_postdata();
} else {
?>
<p>Content I want to show if no posts found.</p>
<?php
// You could load a sub-template/partial here, e.g.:
// get_template_part( 'content', 'none' );
// it won't replace the entire template though
}
Related Posts:
- Use [embed] filter in template files
- Is there a way to list all used/unused WP templates?
- Print WordPress template filename(s) for debugging
- How to force TinyMCE in WordPress to replace newlines with tags and not with
- WooCommerce: Change template for single product page
- 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’
- Gravity Forms Custom Templates [closed]
- add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
- How can I modify the default reset (lost) password email text?
- Programmatically change post templates?
- Gutenberg Editor – Template Doesn’t Match Error
- Need to give custom page template for each language in WPML
- TwentyTen: Overloading template.php files vs. get_template_part
- Post formats template
- Proper way to use get_the_content() in front-page.php and the content-home.php?
- What is a good way to present templated content in WordPress?
- Load template file without a post type
- Plugin settings page template
- What is content.php file that is needed for Jetpack infinite scroll plugin?
- How do you override Post template when using Query Loop block?
- Strange Behaviour with is_home()
- How to create a wordpress template without using any page
- Change location of header.php and footer.php
- Calling an image within the theme folder from inside a post/page?
- Best Constant to use to check if WordPress is running
- Routing dynamic numeric slug to custom template
- WordPress automatically created files like .theme-name / .plugin-name.php [closed]
- Is there any way of viewing revision history on files in WordPress?
- Customize profile.php
- Change wp-signup.php Page Template
- Templates have disappeared from drop down lists
- Getting pages filtered by template assigned
- Use same page template for parent and child pages in a theme
- Template administration Error after WP 4.8 update
- Markup is visible when I view sample data from my template
- if page is parent page redirect to first child with hook / polylang
- Custom template bypassing to pager to index.php
- How to put limit on slider
- What are the main parts of a WordPress Template?
- Display current category and child
- Return get_header and get_footer string instead of echo it
- Different templates for same content, landing page from different URLs (generic, simple)
- Use one template only for custom post type archives?
- lost css when overriding themes templates
- Is there a more efficient way to loop through pages?
- How to create a post template with two sidebars
- Is it possible to register a new template file?
- What template is used for viewing Media Library Files?
- Remove portion of header code from home page only
- Use a separate template for the home page only
- WordPress 3.3.1 single post template
- Create a blank test.php
- Conditional to determine if search.php page is the current template
- How do I remove the word “Blog” from a WordPress Homepage?
- Page Templates not using functions.php
- AMP version of front page without plugin
- Theme settings Page: Settings Api vs Update_Options
- Give wp link pages it’s own template
- /wp-admin/post.php shows 404 template on submit
- Which template.php for /blog
- List Category Posts plugin – underline links [closed]
- Conditional template tag for buddypress pages
- Need help with my template [closed]
- WordPress Template Reverts to default template after changing
- using add_filter in a template_redirect function?
- How does post loop integrate individual page elements
- Content not showing properly with the first load of the page
- Where do I edit what the user sees on my WordPress site?
- User role templates
- Using a SendGrid transactional template with wp_mail
- Language file doesn’t work (poeedit)
- How to configure my blog page
- BuddyPress : how can I call the template WordPress would have chosen (template hierarchy)?
- How to adjust only the template gallery
- Why default template does not show?
- Nested Page Template not showing in page attributes
- Custom Taxonomy Theme file not routing correctly
- Header and footer fail to load with SSL and custom links
- Creating page-templates directory breaks everything!
- Editing the tag pages and using templates
- WordPress not picking up custom templates in sub directory
- Problem displaying replies as part of author’s latest comments on author page
- custom template – override plugin template in child theme – issue with scripts
- Is it better practice to create many page templates, or a a few base templates with custom HTML added via TinyMCE?
- Is it possible to call a template file inside wysiwyg editor? And how?
- Retrieving post ID from current page
- Add pagination to blog
- Styling own template
- WordPress sites translate dynamically generated Homepages
- Choose to show or not show title on a template?
- Add multiple pages to theme customizer
- Single Post Template with Dropdown Option?
- Why is this page using the homepage template and not the one it should?
- Make default template two columns?
- Read more button not working
- Output fields manually in Woocommerce email templates
- Templates to use multiple time within page? [closed]
- Custom template pagination
- My homepage’s width has reduced and I can´t fix it [closed]