$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Is it possible to display post title in reverse word order?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Is it possible to display post title in reverse word order?

matteradmin5PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

There 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:

  1. Take the title.
  2. Explode it into pieces using ' - ' as separator.
  3. Reverse the pieces.
  4. Glue them together using ' - ' as separator again.
  5. Echo the result.
Post a comment

comment list (0)

  1. No comments so far