Reputation: 57
I am trying to get my blog to show a message to visitors when they visit the category main page (ex: www.website.com/category-slug-here/), but can't seem to figure out the Wordpress Loop quite right. Here is what I started with in my theme's index.php file:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
And here is how I tried to alter it:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; else: ?>
<p>Sorry, looks like this category is empty!</p>
<?php endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
However, making this change doesn't seem to yield any results. Am I missing something here? Seems like this should work (but I'm also not a total PHP guru, which is why I came here to consult with the masses). ;)
Upvotes: 0
Views: 475
Reputation: 2398
In wordpress the posts in category are shown in archive.php
page .
Try to write the else condition in archive page instead of index.php
page
Upvotes: 1