让 the_author 在循环中只回显一次
基本上我的网站设置是在主题标题中显示每个页面/帖子的标题。我还设置了在我的作者页面上显示作者姓名(我使用条件来做到这一点)。我遇到的问题是,作者的姓名会根据作者撰写的帖子数量进行回显,而我只希望它回显一次。我有办法做到这一点吗?我意识到它这样做是因为 the_author 必须处于循环中(我的标题中有一个循环来执行此操作)。无论如何都可以在循环之外显示 the_author 吗?
我的网站是 http://www.imagineitstudios.com 。如果您点击主页第一篇文章中的“由 Abel 发布”链接,您就可以看到我在说什么。
感谢您的帮助。
这是我的代码:
<div id="title">
<?php //Check to see if this is an author page ?>
<?php if(is_author()): ?>
<?php while (have_posts()) : the_post(); ?><?php //Creat a mini loop to display the author ?>
<h1><?php the_author();?></h1>
<?php endwhile;?><?php //End of Mini Loop ?>
<?php else :?>
<h1><?php the_title();?></h1>
<?php endif ;?>
</div>
basically I have my site setup to display the title of each page/post in the header of my theme. I also have it setup to display the name of an author on my author pages(I did this using a conditional). The problem I'm having is that the name of the author is echoed for the number of posts the author has written and I only want it to echo once. Is there a way I can do this? I realize that its doing this because the_author has to be in a loop(I have a loop in my header to do this). Is there anyway to be able to display the_author outside of the loop?
My site is http://www.imagineitstudios.com . you can see what I'm talking about if you click on the "Posted by Abel" link on the first post of the home page
Thanks for your help.
Here's my code:
<div id="title">
<?php //Check to see if this is an author page ?>
<?php if(is_author()): ?>
<?php while (have_posts()) : the_post(); ?><?php //Creat a mini loop to display the author ?>
<h1><?php the_author();?></h1>
<?php endwhile;?><?php //End of Mini Loop ?>
<?php else :?>
<h1><?php the_title();?></h1>
<?php endif ;?>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码:
You can use the following code: