admin管理员组文章数量:1130349
I created alphabetical list of members(custom post) using first letter of title. Therefore title was in format 'Surname - Name'. Now on single member page I need somehow to reverse order to 'Name - Surname'. Is it possible?
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
I created alphabetical list of members(custom post) using first letter of title. Therefore title was in format 'Surname - Name'. Now on single member page I need somehow to reverse order to 'Name - Surname'. Is it possible?
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
Share
Improve this question
asked Nov 22, 2018 at 21:51
Vedran SadićVedran Sadić
311 bronze badge
1
|
1 Answer
Reset to default 2There will be a lot of ways to solve this. One of them is to modify template of single CPT post and replace:
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
with:
<h1 class="entry-title"><?php
$separator = ' - ';
echo implode( $separator, array_reverse( explode( $separator, get_the_title() ) ) );
?></h1>
What it will do is:
- Take the title.
- Explode it into pieces using ' - ' as separator.
- Reverse the pieces.
- Glue them together using ' - ' as separator again.
- Echo the result.
I created alphabetical list of members(custom post) using first letter of title. Therefore title was in format 'Surname - Name'. Now on single member page I need somehow to reverse order to 'Name - Surname'. Is it possible?
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
I created alphabetical list of members(custom post) using first letter of title. Therefore title was in format 'Surname - Name'. Now on single member page I need somehow to reverse order to 'Name - Surname'. Is it possible?
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
Share
Improve this question
asked Nov 22, 2018 at 21:51
Vedran SadićVedran Sadić
311 bronze badge
1
-
Do you need the
-also in between? And will there be just 2 words? If there are 3 or more words, how would you like to display? – Akshat Commented Nov 22, 2018 at 22:03
1 Answer
Reset to default 2There will be a lot of ways to solve this. One of them is to modify template of single CPT post and replace:
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
with:
<h1 class="entry-title"><?php
$separator = ' - ';
echo implode( $separator, array_reverse( explode( $separator, get_the_title() ) ) );
?></h1>
What it will do is:
- Take the title.
- Explode it into pieces using ' - ' as separator.
- Reverse the pieces.
- Glue them together using ' - ' as separator again.
- Echo the result.
本文标签: Is it possible to display post title in reverse word order
版权声明:本文标题:Is it possible to display post title in reverse word order? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749158822a2325052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


-also in between? And will there be just 2 words? If there are 3 or more words, how would you like to display? – Akshat Commented Nov 22, 2018 at 22:03