dplm47571 2016-01-21 22:23
浏览 19
已采纳

当类别中没有帖子时,让Wordpress显示消息

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). ;)

  • 写回答

1条回答 默认 最新

  • dongpo5207 2016-01-22 04:36
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分