【问题标题】:How can I show a custom message instead "No Results Found" for empty categories in WordPress?如何在 WordPress 中为空类别显示自定义消息而不是“未找到结果”?
【发布时间】:2020-04-05 17:42:43
【问题描述】:

我已经搜索了很多时间并试图找出解决方案,但我找不到。我的网站上有一些空白类别。我想为所有这些类别显示一条自定义消息。我该怎么做?

【问题讨论】:

  • 请查看我的回答

标签: wordpress categories


【解决方案1】:

如果 category.php 文件不存在,则需要修改或创建该文件并将此代码放在那里:

<?php if ( have_posts() ) : ?>

// The Loop
while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

<div class="entry">
<?php the_content(); ?>

 <p class="postmetadata"><?php
  comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments closed');
?></p>
</div>

<?php endwhile; 

else: ?>
<p>**YOU CUSTOM MESSAGE TO SHOW "NO POSTS" MESSAGE**</p>


<?php endif; ?>

【讨论】:

  • 这有效并显示所有类别的自定义消息,即使类别有一些帖子。
猜你喜欢
  • 2021-06-27
  • 2013-12-25
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 2014-09-21
  • 2019-02-25
  • 1970-01-01
  • 2020-05-14
相关资源
最近更新 更多