- This topic has 13 replies, 2 voices, and was last updated 2 years, 7 months ago by Elvin.
-
AuthorPosts
-
September 18, 2021 at 8:31 am #1934834Eduardo Garcia
Hello, we have a taxonomy on the web that is “dates” that is equivalent to the months of the year, currently it shows them in reverse order, and we would like to change it, is it possible in elements?
This is the code we have installed:
<h1>
{{post_title}}
</h1>
<h2>
{{custom_field.subtitulo_h2}}
</h2>
<h5>
{{post_terms.category}} | {{post_terms.fechas}} | {{post_terms.paises}}
</h5>And so it shows:
https://ofertassingles.com/aventura-andaluza/The problem is that when showing the dates it does it from December to September and we want to change the order if possible.
Thanks.
September 18, 2021 at 6:57 pm #1935150ElvinStaffCustomer SupportHi Eduardo,
Unfortunately, that’s not possible with the date template tag.
That tag uses the WordPress Core function
get_the_term_list()
and this listing sorts terms by name (alphabetical). That’s why D (December) goes before S(September).That’s likely sorted as April > August > December > February > January > June > July > March > May > November > October > September.
If you want to change the sorting, you may have to modify the HTML of the page hero a bit and sort things using CSS.
Example HTML:
<h1> {{post_title}} </h1> <h2> {{custom_field.subtitulo_h2}} </h2> <h5> <span class="hero-terms categoria">{{post_terms.category}}</span> | <span class="hero-terms fechas">{{post_terms.fechas}}</span> | <span class="hero-terms paises">{{post_terms.paises}}</span> </h5>
You then sort things by using this CSS:
.page-hero h5 .hero-terms { display: inline-flex; flex-direction: row; } .page-hero h5 .fechas a[href*="diciembre"]{ order: 12; } .page-hero h5 .fechas a[href*="nobiembre"]{ order: 11; } .page-hero h5 .fechas a[href*="octubre"]{ order: 10; } .page-hero h5 .fechas a[href*="septiembre"]{ order: 9; } .page-hero h5 .fechas a[href*="agosto"]{ order: 8; } .page-hero h5 .fechas a[href*="agosto"]{ order: 7; } .page-hero h5 .fechas a[href*="julio"]{ order: 6; } .page-hero h5 .fechas a[href*="junio"]{ order: 5; } .page-hero h5 .fechas a[href*="abril"]{ order: 4; } .page-hero h5 .fechas a[href*="marzo"]{ order: 3; } .page-hero h5 .fechas a[href*="febrero"]{ order: 2; } .page-hero h5 .fechas a[href*="enero"]{ order: 1; }
September 19, 2021 at 3:02 am #1935416Eduardo GarciaPerfect, now order them correctly, but how could I separate each of these taxonomies by commas, all the commas appear at the beginning and the text all together, can you help me?
September 19, 2021 at 8:07 pm #1936105ElvinStaffCustomer SupportTry adding this PHP snippet to remove the default separator for the category only.
add_filter( 'generate_category_list_output', function($output){ $categories_list = get_the_category_list(); $output = sprintf('<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ', esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list, apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' ) ); return $output; });
You then add this CSS to add the commas back:
.page-hero h5 .fechas a:not(a[href*="diciembre"]):after{ content:", "; margin-right: 5px; }
September 20, 2021 at 9:50 am #1936937Eduardo GarciaIt works perfect, it would only remain that it does not show the commas that come out in a row after category | ,,,,
September 20, 2021 at 4:34 pm #1937216ElvinStaffCustomer Supporton this line –
get_the_category_list();
– can you change it toget_the_category_list(' ');
? This is to remove the old separator.September 22, 2021 at 12:57 am #1938743Eduardo GarciaGood morning, first of all thank you for your attention
It just doesn’t work properly.
I have added an image that corresponds to two urls
Tanzania → https://ofertassingles.com/gran-aventura-tanzania/
Morocco → https://ofertassingles.com/singles-a-marorca/We see that in the image above there is one “,” before Singles in September, and another at the end of Singles in November.
In the image below they come out “,,,” before Singles in September and at the end after December is correct.
Is it possible to remove all the starting and ending commas?
Thanks again
September 22, 2021 at 1:12 am #1938758ElvinStaffCustomer SupportThe PHP filter I’ve provided should’ve removed the
,,,
s.Can you tell us how you’ve applied it to your site? PHP needs its own code area – https://docs.generatepress.com/article/adding-php/
September 22, 2021 at 5:08 am #1938980Eduardo GarciaWe include it in the functions.php of child theme
September 22, 2021 at 8:25 pm #1939796ElvinStaffCustomer SupportAh I forgot post tag terms use a different filter. My bad.
Let’s try this instead:
add_filter( 'generate_page_hero_terms_separator', function() { return ''; } );
And then wrap the tag terms on its own wrapper HTML so we re-add the comma to it as well as the new filter I’ve provided will remove the
,
for all terms.September 23, 2021 at 1:03 am #1939945Eduardo GarciaHi,
it works perfectly, but it also removes it in the rest of the taxonomies and we only want it to remove it in the dates taxonomy, which applies only to taxonomy = fechas
https://ofertassingles.com/singles-a-marorca/
https://ofertassingles.com/singles-a-egipto/Thanks,
September 23, 2021 at 1:17 am #1939955ElvinStaffCustomer SupportYes, that’s right. That’s expected.
We then add the
,
back using CSS.try this.
.page-hero .paises a:not(:last-child):after, .page-hero .categoria a:not(:last-child):after { content: ", "; margin-right: 5px; }
September 23, 2021 at 3:37 am #1940085Eduardo GarciaGreat, it works perfectly
Thank you very much for your attention and wisdom Elvin, you have been a great help to me.
Have a happy day !!!
September 26, 2021 at 6:28 pm #1943780ElvinStaffCustomer SupportNo problem. Glad to be of any help. Stay safe! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.