Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1263855

    Hi. How can I put commas to separate the taxonomies even though they are from different groups of taxonomies? In the attached image, only separate taxonomies that belong to the same group with commas. I indicate in green where it does put the commas (same group of taxonomies) and in red where it does not put them and I would like it to have

    #1264486

    Hey jeiceta,

    Thank you for the inquiry.

    How do you define the taxonomy group? Currently, it just loops through the array of taxonomy terms and render the comma right after every item regardless of their grouping if they actually have one.

    Best regards,
    Ismael

    #1264603

    Hi Ismael,

    I have created a content type and I have added some categories as you see in the image. Categories in red

    There are 4 different categories that in turn contain several taxonomies. Those that are from the same group of taxonomies are separated by commas, but those that are of a different category are not, as you can see in my first post. Where if they come out with green arrows and where they don’t come out with red arrows. It should be, according to the example you see in the image of my first publication in the first entry, 1954, like this:SIGLO XX, FRANCIA, ARTE, PUERTO DE LA CRUZ, SANTA CRUZ DE TENERIFE

    • This reply was modified 3 years, 12 months ago by jeiceta.
    #1265369

    Hi,

    In WordPress, category and taxonomy are the same thing. Are you referring to the terms inside the categories or taxonomies? If so, you may need to get the WP_Term object or info based on the term ID. You can then check the taxonomy info of the current item and compare it against the taxonomy of the previous term. If the taxonomy of the current item is the same as the previous one, then we will not render a comma.

    You will find the category loop in includes > loop-index.php file around line 285.

       if( ! empty( $taxonomies ) )
                    {
                        foreach( $taxonomies as $taxonomy )
                        {
                            if( ! in_array( $taxonomy, $excluded_taxonomies ) )
                            {
                                $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
                            }
                        }
                    }
    
    

    You may need to replace get_the_term_list with get_the_terms function to get a full list of the WP_Terms.

    UPDATE: Please ignore my message above, just try to edit the includes > loop-index.php file and around line 291, try to place a comma right after every set of terms.

    $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ', ';
    

    Best regards,
    Ismael

    #1265427

    Hi Imael, I make the distinction of categories and taxonomies to differentiate. As you can see in the screenshot, I have 4 categories: Siglos, Países, Temáticas y Municipios. . I call a category to Países and taxonomies to, for example, Alemania.

    What you tell me I had already tried. But I tell you the result.. If the 4 categories are represented, put a comma at the end. If it’s not 4 o’clock, put the commas anyway. I put examples. If the 4 categories are there, it would look something like this: “Siglo XX , Reino Unido , Literatura , Puerto de la Cruz , ” With the comma at the end. And if, for example, I don’t put the last category, it puts it like this: “Siglo XX , Reino Unido , Literatura ,, ” IIt also puts the comma at the end and of the missing category. I have broken my head to see how to solve it, but nothing. Can you help me?

    • This reply was modified 3 years, 11 months ago by jeiceta.
    #1266823

    Hi,

    Did you try the suggestion above regarding WP_Term object? You may need to loop through each term and check if the previous one belongs to the same taxonomy as the current one. If this is true, then render the comma.

    Is the site live? We could also remove the unnecessary comma in the front end using Javascript. Please post the site or page URL containing the posts with categories so that we could check the elements.

    Best regards,
    Ismael

    #1266847
    This reply has been marked as private.
    #1267494

    Hi Ismael,

    If it can be done with Javascript and it’s done, I’d like to know how. Although I have already solved it.

    This is the original code:

    $cats .= get_the_term_list( $the_id, $taxonomy, ”, ‘, ‘, ‘ ‘ ) . ‘ ‘;

    I’ve added:

    <span class=”coma”>, </span>

    It stays like this:

    $cats .= get_the_term_list($the_id, $taxonomy, ”, ‘, ‘, ‘<span class=”coma”>, </span>’).’ ‘;

    And the coma class I have given this style:

    .coma:last-child {
    display: none;
    }

    And the problem has been solved. This in the link that I provided you cannot be seen because I did it on the web that we want to publish. But, finally, I solved it.

    Thanks for your attention.

    • This reply was modified 3 years, 11 months ago by jeiceta.
    #1267647

    Hi,

    Great! Glad to know that you have found a solution. In hindsight, using Javascript is bit of an overkill. Please feel free to open a new thread if you need anything else.

    Have a nice day.

    Best regards,
    Ismael

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘How to put commas to separate taxonomies from different groups of taxonomies’ is closed to new replies.