Community Forums › Forums › Archived Forums › General Discussion › show correct singular/plural-text in headline of tag-pages after wp_query
- This topic has 7 replies, 2 voices, and was last updated 5 years, 2 months ago by Soenke.
-
AuthorPosts
-
February 1, 2019 at 5:02 am #489195SoenkeParticipant
Hallo,
on the headline of tag-pages I show the tag-name and I show the count of the posts in the archive with the following code:
<?php global $post, $wp_query; ?>
https://rechtsanwalt-und-sozialrecht.de
<?php
if(is_tag()) { ?>
<div class="headline"><h1><?php printf(__('%s'), single_cat_title('', false) ); ?></h1>
(<?php echo $wp_query->found_posts; ?> article to the keyword)
</div>
<?php }
?>
I would like to customize the text behind the number of the count with the correct singular-/plural-form:
tag-name
(1 article to the keyword)
tag-name
(2 articles to the keyword)
…
I do not know how to solve the problem (even after trying to solve it in hours and hours).
Thanks for help!February 1, 2019 at 10:10 am #489198Victor FontModeratorecho <?php echo $wp_query->found_posts . ($wp_query->found_posts == 1) ? 'article' : 'articles'; ?>
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 4, 2019 at 2:29 am #489280SoenkeParticipantHallo Victor,
thank you very much for the answer!
I added:
(<?php echo $wp_query->found_posts; echo $wp_query->found_posts . ($wp_query->found_posts == 1) ? 'article' : 'articles'; ?> to the keyword)
... but something doesn't work:
I use the code above in "simple hooks" - I always get the singular form (article).
Greetings ...
February 4, 2019 at 7:26 am #489286Victor FontModeratorWhere did you add this in Simple Hooks?
You have to make sure you're placing it into the correct hook and the right priority.
Simple hooks may not be the right way to do this. You may have to use the genesis_term_intro_text_output filter or genesis_archive_title_descriptions action.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 4, 2019 at 10:03 am #489289SoenkeParticipantHallo,
I added it in genesis_before_loop Hook.
The output without the correct plural form works. "Execute php on this hook?" is enabled.
Thank you for answering!
February 4, 2019 at 1:38 pm #489295Victor FontModeratorThe code you added is not the code I provided for you. What you added is echoing the # of found posts twice.
I don't know that I can help you further without looking into the back end of the site. Besides, when I look at the site link in the first post, the site is in German. It's confusing me.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 8, 2019 at 11:30 am #489424SoenkeParticipantI deleted simple hooks an now there is the following code in my functions.php:
add_filter( 'genesis_before_loop', 'tag_title');
function tag_title() {
if(is_tag()) {
global $post, $wp_query;
printf(__('<h1>%s</h1>'), single_cat_title('', false) );
echo "(";
echo $wp_query->found_posts;
echo " Artikel zum Stichwort)";
echo "<br/> <br/>";
}}if I change the phrase "echo $wp_query->found_posts;" with the given code "echo $wp_query->found_posts . ($wp_query->found_posts == 1) ? 'article' : 'articles';" the plural-form isn't shown. Only
... -> tag-title<-
(article Artikel zum Stichwort)is shown. This result is shown as well tag archive has one or as plural results. Without the given code the result is:
... -> tag-title<-
(1 Artikel zum Stichwort) for a single result and... -> tag-title<-
(2 Artikel zum Stichwort) for plural resultsI do not know how to solve the problem ...
Greetings ...
February 20, 2019 at 9:01 am #489634SoenkeParticipantHallo,
I found the following solution:
if ($wp_query->found_posts==1){
echo " article)";
}
else echo " articles)";Greetings
-
AuthorPosts
- The topic ‘show correct singular/plural-text in headline of tag-pages after wp_query’ is closed to new replies.