[Support request] {{post_terms.taxonomy}} custom ORDER

Home Forums Support [Support request] {{post_terms.taxonomy}} custom ORDER

Home Forums Support {{post_terms.taxonomy}} custom ORDER

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1934834
    Eduardo 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.

    #1935150
    Elvin
    Staff
    Customer Support

    Hi 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; }
    #1935416
    Eduardo Garcia

    Perfect, 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?

    https://ofertassingles.com/singles-a-marruecos/

    #1936105
    Elvin
    Staff
    Customer Support

    Try 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;
    }
    #1936937
    Eduardo Garcia

    It works perfect, it would only remain that it does not show the commas that come out in a row after category | ,,,,

    #1937216
    Elvin
    Staff
    Customer Support

    on this line – get_the_category_list(); – can you change it to get_the_category_list(' ');? This is to remove the old separator.

    #1938743
    Eduardo Garcia

    Good 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 + Morocco

    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

    #1938758
    Elvin
    Staff
    Customer Support

    The 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/

    #1938980
    Eduardo Garcia

    We include it in the functions.php of child theme

    https://ofertassingles.com/wp-content/uploads/2021/09/code-gp.jpg

    #1939796
    Elvin
    Staff
    Customer Support

    Ah 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.

    #1939945
    Eduardo Garcia

    Hi,

    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,

    #1939955
    Elvin
    Staff
    Customer Support

    Yes, 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;
    }
    #1940085
    Eduardo Garcia

    Great, 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 !!!

    #1943780
    Elvin
    Staff
    Customer Support

    No problem. Glad to be of any help. Stay safe! 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.