I’ll build this as a strong WordPress theme template part for the “no posts found” state, with search form, helpful suggestions, popular categories/tags, recent posts, archive links, and accessibility/security best practices.
Yes friend — in rx-theme/template-parts/content/content-none.php, you can make a very advanced “No content found” template. This file will show when WordPress does not find posts, search results, category posts, archive posts, etc.
Create or replace this file:
template-parts/content/content-none.php
<?php
/**
* Template part for displaying a message that posts cannot be found.
*
* @package Rx_Theme
* @since 1.0.0
*/
defined( 'ABSPATH' ) || exit;
$rx_is_search = is_search();
$rx_is_home = is_home();
$rx_is_archive = is_archive();
$rx_is_404 = is_404();
$rx_search_query = get_search_query();
$rx_current_url = home_url( add_query_arg( array(), $GLOBALS['wp']->request ?? '' ) );
$rx_home_url = home_url( '/' );
$rx_blog_url = get_permalink( get_option( 'page_for_posts' ) );
$rx_blog_url = $rx_blog_url ? $rx_blog_url : $rx_home_url;
$rx_post_type = get_query_var( 'post_type' );
$rx_post_type_name = '';
if ( is_array( $rx_post_type ) ) {
$rx_post_type = reset( $rx_post_type );
}
if ( ! empty( $rx_post_type ) && post_type_exists( $rx_post_type ) ) {
$rx_post_type_object = get_post_type_object( $rx_post_type );
if ( $rx_post_type_object && ! empty( $rx_post_type_object->labels->singular_name ) ) {
$rx_post_type_name = $rx_post_type_object->labels->singular_name;
}
}
$rx_title = __( 'Nothing Found', 'rx-theme' );
if ( $rx_is_search ) {
$rx_title = __( 'No Search Results Found', 'rx-theme' );
} elseif ( $rx_is_404 ) {
$rx_title = __( 'Page Not Found', 'rx-theme' );
} elseif ( $rx_is_archive ) {
$rx_title = __( 'No Posts Found in This Archive', 'rx-theme' );
} elseif ( current_user_can( 'publish_posts' ) && $rx_is_home ) {
$rx_title = __( 'Ready to Publish Your First Post?', 'rx-theme' );
}
$rx_recent_posts = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
$rx_popular_posts = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'comment_count',
'order' => 'DESC',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
$rx_categories = get_categories(
array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
'hide_empty' => true,
)
);
$rx_tags = get_tags(
array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 15,
'hide_empty' => true,
)
);
$rx_archives = wp_get_archives(
array(
'type' => 'monthly',
'limit' => 8,
'echo' => false,
'show_post_count' => true,
)
);
$rx_common_searches = apply_filters(
'rx_theme_content_none_common_searches',
array(
__( 'Health', 'rx-theme' ),
__( 'Disease', 'rx-theme' ),
__( 'Symptoms', 'rx-theme' ),
__( 'Diagnosis', 'rx-theme' ),
__( 'Treatment', 'rx-theme' ),
__( 'Medicine', 'rx-theme' ),
__( 'Nutrition', 'rx-theme' ),
__( 'Prevention', 'rx-theme' ),
)
);
$rx_quick_links = apply_filters(
'rx_theme_content_none_quick_links',
array(
array(
'label' => __( 'Home', 'rx-theme' ),
'url' => $rx_home_url,
'icon' => '🏠',
),
array(
'label' => __( 'Blog', 'rx-theme' ),
'url' => $rx_blog_url,
'icon' => '📝',
),
array(
'label' => __( 'Latest Posts', 'rx-theme' ),
'url' => $rx_blog_url,
'icon' => '📰',
),
array(
'label' => __( 'Contact', 'rx-theme' ),
'url' => home_url( '/contact/' ),
'icon' => '✉️',
),
)
);
do_action( 'rx_theme_before_content_none' );
?>
<section id="post-<?php echo esc_attr( get_the_ID() ); ?>" <?php post_class( 'rx-content-none rx-empty-state' ); ?> aria-labelledby="rx-content-none-title">
<div class="rx-content-none__inner">
<header class="rx-content-none__header">
<div class="rx-content-none__icon" aria-hidden="true">
<?php if ( $rx_is_search ) : ?>
🔎
<?php elseif ( $rx_is_404 ) : ?>
⚠️
<?php elseif ( current_user_can( 'publish_posts' ) && $rx_is_home ) : ?>
✍️
<?php else : ?>
📭
<?php endif; ?>
</div>
<h1 id="rx-content-none-title" class="rx-content-none__title">
<?php echo esc_html( apply_filters( 'rx_theme_content_none_title', $rx_title ) ); ?>
</h1>
<div class="rx-content-none__description">
<?php if ( current_user_can( 'publish_posts' ) && $rx_is_home ) : ?>
<p>
<?php esc_html_e( 'Your site is ready, but no posts have been published yet. Start writing your first article and it will appear here automatically.', 'rx-theme' ); ?>
</p>
<p>
<a class="rx-button rx-button--primary" href="<?php echo esc_url( admin_url( 'post-new.php' ) ); ?>">
<?php esc_html_e( 'Create Your First Post', 'rx-theme' ); ?>
</a>
</p>
<?php elseif ( $rx_is_search ) : ?>
<p>
<?php
printf(
esc_html__( 'We could not find any result for “%s”. Try another keyword, check spelling, or use the suggestions below.', 'rx-theme' ),
esc_html( $rx_search_query )
);
?>
</p>
<?php elseif ( $rx_is_404 ) : ?>
<p>
<?php esc_html_e( 'The page you are looking for may have been moved, deleted, renamed, or never existed. You can search the site or visit one of the helpful links below.', 'rx-theme' ); ?>
</p>
<?php elseif ( $rx_is_archive ) : ?>
<p>
<?php esc_html_e( 'There are no published posts in this section yet. Please try another archive, category, tag, or search keyword.', 'rx-theme' ); ?>
</p>
<?php elseif ( ! empty( $rx_post_type_name ) ) : ?>
<p>
<?php
printf(
esc_html__( 'No %s content is available right now. Please search again or explore the latest posts.', 'rx-theme' ),
esc_html( strtolower( $rx_post_type_name ) )
);
?>
</p>
<?php else : ?>
<p>
<?php esc_html_e( 'No content matched your request. Please try a different search term or explore the latest articles.', 'rx-theme' ); ?>
</p>
<?php endif; ?>
</div>
</header>
<div class="rx-content-none__search">
<h2 class="rx-content-none__section-title">
<?php esc_html_e( 'Search This Website', 'rx-theme' ); ?>
</h2>
<?php get_search_form(); ?>
<?php if ( $rx_is_search && ! empty( $rx_search_query ) ) : ?>
<div class="rx-search-help">
<p>
<?php esc_html_e( 'Search tips:', 'rx-theme' ); ?>
</p>
<ul>
<li><?php esc_html_e( 'Use fewer words.', 'rx-theme' ); ?></li>
<li><?php esc_html_e( 'Check spelling carefully.', 'rx-theme' ); ?></li>
<li><?php esc_html_e( 'Try a broader medical or health keyword.', 'rx-theme' ); ?></li>
<li><?php esc_html_e( 'Search by symptom, disease name, test name, or treatment name.', 'rx-theme' ); ?></li>
</ul>
</div>
<?php endif; ?>
</div>
<?php if ( ! empty( $rx_common_searches ) && is_array( $rx_common_searches ) ) : ?>
<div class="rx-content-none__common-searches">
<h2 class="rx-content-none__section-title">
<?php esc_html_e( 'Try Popular Search Topics', 'rx-theme' ); ?>
</h2>
<div class="rx-keyword-cloud">
<?php foreach ( $rx_common_searches as $rx_keyword ) : ?>
<?php
$rx_keyword = sanitize_text_field( $rx_keyword );
if ( empty( $rx_keyword ) ) {
continue;
}
?>
<a class="rx-keyword-cloud__item" href="<?php echo esc_url( get_search_link( $rx_keyword ) ); ?>">
<?php echo esc_html( $rx_keyword ); ?>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if ( ! empty( $rx_quick_links ) && is_array( $rx_quick_links ) ) : ?>
<nav class="rx-content-none__quick-links" aria-label="<?php esc_attr_e( 'Helpful links', 'rx-theme' ); ?>">
<h2 class="rx-content-none__section-title">
<?php esc_html_e( 'Helpful Links', 'rx-theme' ); ?>
</h2>
<ul class="rx-quick-link-list">
<?php foreach ( $rx_quick_links as $rx_link ) : ?>
<?php
if ( empty( $rx_link['url'] ) || empty( $rx_link['label'] ) ) {
continue;
}
$rx_link_icon = ! empty( $rx_link['icon'] ) ? $rx_link['icon'] : '🔗';
?>
<li class="rx-quick-link-list__item">
<a class="rx-quick-link-list__link" href="<?php echo esc_url( $rx_link['url'] ); ?>">
<span class="rx-quick-link-list__icon" aria-hidden="true">
<?php echo esc_html( $rx_link_icon ); ?>
</span>
<span class="rx-quick-link-list__text">
<?php echo esc_html( $rx_link['label'] ); ?>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</nav>
<?php endif; ?>
<?php if ( $rx_recent_posts->have_posts() ) : ?>
<section class="rx-content-none__recent-posts" aria-labelledby="rx-recent-posts-title">
<h2 id="rx-recent-posts-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Latest Articles', 'rx-theme' ); ?>
</h2>
<div class="rx-empty-grid rx-empty-grid--recent">
<?php
while ( $rx_recent_posts->have_posts() ) :
$rx_recent_posts->the_post();
?>
<article <?php post_class( 'rx-empty-card rx-empty-card--post' ); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<a class="rx-empty-card__thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php
the_post_thumbnail(
'medium',
array(
'class' => 'rx-empty-card__image',
'loading' => 'lazy',
'alt' => the_title_attribute(
array(
'echo' => false,
)
),
)
);
?>
</a>
<?php endif; ?>
<div class="rx-empty-card__body">
<h3 class="rx-empty-card__title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<div class="rx-empty-card__meta">
<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>">
<?php echo esc_html( get_the_date() ); ?>
</time>
<?php if ( comments_open() || get_comments_number() ) : ?>
<span class="rx-empty-card__comments">
<?php
printf(
esc_html(
_n(
'%s comment',
'%s comments',
get_comments_number(),
'rx-theme'
)
),
esc_html( number_format_i18n( get_comments_number() ) )
);
?>
</span>
<?php endif; ?>
</div>
<?php if ( has_excerpt() ) : ?>
<p class="rx-empty-card__excerpt">
<?php echo esc_html( wp_trim_words( get_the_excerpt(), 18, '…' ) ); ?>
</p>
<?php endif; ?>
<a class="rx-empty-card__read-more" href="<?php the_permalink(); ?>">
<?php esc_html_e( 'Read More', 'rx-theme' ); ?>
<span class="screen-reader-text">
<?php echo esc_html( get_the_title() ); ?>
</span>
</a>
</div>
</article>
<?php endwhile; ?>
</div>
</section>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php if ( $rx_popular_posts->have_posts() ) : ?>
<section class="rx-content-none__popular-posts" aria-labelledby="rx-popular-posts-title">
<h2 id="rx-popular-posts-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Popular Discussions', 'rx-theme' ); ?>
</h2>
<ol class="rx-popular-list">
<?php
while ( $rx_popular_posts->have_posts() ) :
$rx_popular_posts->the_post();
?>
<li class="rx-popular-list__item">
<a class="rx-popular-list__link" href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<span class="rx-popular-list__count">
<?php
printf(
esc_html(
_n(
'%s comment',
'%s comments',
get_comments_number(),
'rx-theme'
)
),
esc_html( number_format_i18n( get_comments_number() ) )
);
?>
</span>
</li>
<?php endwhile; ?>
</ol>
</section>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php if ( ! empty( $rx_categories ) ) : ?>
<section class="rx-content-none__categories" aria-labelledby="rx-categories-title">
<h2 id="rx-categories-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Browse Categories', 'rx-theme' ); ?>
</h2>
<ul class="rx-category-list">
<?php foreach ( $rx_categories as $rx_category ) : ?>
<li class="rx-category-list__item">
<a class="rx-category-list__link" href="<?php echo esc_url( get_category_link( $rx_category ) ); ?>">
<span class="rx-category-list__name">
<?php echo esc_html( $rx_category->name ); ?>
</span>
<span class="rx-category-list__count">
<?php
printf(
esc_html(
_n(
'%s post',
'%s posts',
(int) $rx_category->count,
'rx-theme'
)
),
esc_html( number_format_i18n( (int) $rx_category->count ) )
);
?>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
<?php if ( ! empty( $rx_tags ) ) : ?>
<section class="rx-content-none__tags" aria-labelledby="rx-tags-title">
<h2 id="rx-tags-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Browse Tags', 'rx-theme' ); ?>
</h2>
<div class="rx-tag-cloud">
<?php foreach ( $rx_tags as $rx_tag ) : ?>
<a class="rx-tag-cloud__item" href="<?php echo esc_url( get_tag_link( $rx_tag ) ); ?>">
<?php echo esc_html( $rx_tag->name ); ?>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $rx_archives ) ) : ?>
<section class="rx-content-none__archives" aria-labelledby="rx-archives-title">
<h2 id="rx-archives-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Monthly Archives', 'rx-theme' ); ?>
</h2>
<ul class="rx-archive-list">
<?php echo wp_kses_post( $rx_archives ); ?>
</ul>
</section>
<?php endif; ?>
<?php if ( class_exists( 'WooCommerce' ) ) : ?>
<?php
$rx_products = new WP_Query(
array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 4,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
?>
<?php if ( $rx_products->have_posts() ) : ?>
<section class="rx-content-none__products" aria-labelledby="rx-products-title">
<h2 id="rx-products-title" class="rx-content-none__section-title">
<?php esc_html_e( 'Featured Products', 'rx-theme' ); ?>
</h2>
<div class="rx-empty-grid rx-empty-grid--products">
<?php
while ( $rx_products->have_posts() ) :
$rx_products->the_post();
global $product;
?>
<article <?php post_class( 'rx-empty-card rx-empty-card--product' ); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<a class="rx-empty-card__thumbnail" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'woocommerce_thumbnail' ); ?>
</a>
<?php endif; ?>
<div class="rx-empty-card__body">
<h3 class="rx-empty-card__title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php if ( $product && is_a( $product, 'WC_Product' ) ) : ?>
<div class="rx-empty-card__price">
<?php echo wp_kses_post( $product->get_price_html() ); ?>
</div>
<?php endif; ?>
<a class="rx-empty-card__read-more" href="<?php the_permalink(); ?>">
<?php esc_html_e( 'View Product', 'rx-theme' ); ?>
</a>
</div>
</article>
<?php endwhile; ?>
</div>
</section>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endif; ?>
<section class="rx-content-none__actions" aria-labelledby="rx-actions-title">
<h2 id="rx-actions-title" class="screen-reader-text">
<?php esc_html_e( 'Next Actions', 'rx-theme' ); ?>
</h2>
<div class="rx-action-buttons">
<a class="rx-button rx-button--primary" href="<?php echo esc_url( $rx_home_url ); ?>">
<?php esc_html_e( 'Back to Homepage', 'rx-theme' ); ?>
</a>
<a class="rx-button rx-button--secondary" href="<?php echo esc_url( $rx_blog_url ); ?>">
<?php esc_html_e( 'View Latest Posts', 'rx-theme' ); ?>
</a>
<?php if ( ! empty( $rx_search_query ) ) : ?>
<a class="rx-button rx-button--ghost" href="<?php echo esc_url( get_search_link() ); ?>">
<?php esc_html_e( 'Clear Search', 'rx-theme' ); ?>
</a>
<?php endif; ?>
<button class="rx-button rx-button--ghost" type="button" onclick="window.history.length > 1 ? window.history.back() : window.location.href='<?php echo esc_url( $rx_home_url ); ?>';">
<?php esc_html_e( 'Go Back', 'rx-theme' ); ?>
</button>
</div>
</section>
</div>
<?php
/**
* JSON-LD SearchAction schema for no-result pages.
*/
$rx_search_schema = array(
'@context' => 'https://schema.org',
'@type' => 'WebSite',
'name' => get_bloginfo( 'name' ),
'url' => $rx_home_url,
'potentialAction' => array(
'@type' => 'SearchAction',
'target' => add_query_arg(
array(
's' => '{search_term_string}',
),
$rx_home_url
),
'query-input' => 'required name=search_term_string',
),
);
?>
<script type="application/ld+json">
<?php echo wp_json_encode( $rx_search_schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ); ?>
</script>
</section>
<?php
do_action( 'rx_theme_after_content_none' );
This version includes:
Search form, search tips, latest posts, popular posts, categories, tags, monthly archives, helpful links, WooCommerce product support, admin “create first post” button, schema markup, action buttons, accessibility labels, escaping, filters, and hooks.
To load this file inside index.php, archive.php, search.php, or other templates, use:
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content/content', get_post_type() );
endwhile;
the_posts_pagination();
else :
get_template_part( 'template-parts/content/content', 'none' );
endif;
?>