• Resolved brad1004

    (@brad1004)


    Hi All

    I am trying to add a message to a custom post type archive page if a taxonomy filter brings no post results.

    This is the code on my custom archive page

    <?php get_header(); ?>
    <section id="content" role="main">
    <header class="header">
    <?php if(function_exists('show_beautiful_filters')) echo show_beautiful_filters('p-showcase'); ?>
    </header>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div id="showcases-arch">
    <div class="showcase-thumb"><img src="<?php the_field('sho-thumb'); ?>"/></div>
    <div class="showcase-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></div>
    <div class="showcase-details"><?php the_excerpt(); ?> <br/><a href="<?php the_permalink(); ?>"> View the full showcase</a></div></div>
    <?php endwhile; endif; ?>
    <?php get_template_part( 'nav', 'below' ); ?>
    </section>
    <?php get_footer(); ?>

    Sorry my php ability is around the copy and paste level. I have tried a few variants using <?php else but they all have syntax errors

    Any help will be appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Brad,

    You can just change it to:

    <?php get_header(); ?>
    
    <section id="content" role="main">
    
    	<header class="header">
    		<?php if(function_exists('show_beautiful_filters')) echo show_beautiful_filters('p-showcase'); ?>
    	</header>
    
    	<?php if ( have_posts() ) : ?> 
    
    		<?php while ( have_posts() ) : the_post(); ?>
    			<div id="showcases-arch">
    				<div class="showcase-thumb"><img src="<?php the_field('sho-thumb'); ?>"/></div>
    				<div class="showcase-title">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a>
    				</div>
    				<div class="showcase-details">
    					<?php the_excerpt(); ?> <br/><a href="<?php the_permalink(); ?>"> View the full showcase</a>
    				</div>
    			</div>
    		<?php endwhile; ?>
    
    		<?php get_template_part( 'nav', 'below' ); ?>
    
    	<?php else: ?>
    
    		<h1><?php _e('No posts found'); ?></h1>
    
    	<?php endif; ?>
    
    </section>
    
    <?php get_footer(); ?>
    Thread Starter brad1004

    (@brad1004)

    Hi Jonathan

    Thank you very much – works perfectly.

    Much indebted for your help!

    Have a good weekend.

    Kind regards
    Brad

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add "No Posts Found" message to CPT archive page’ is closed to new replies.