• Hi there!

    I’m using this function right now in my theme to show for each project his custom taxonomy. In this case, the custom taxonomy is tipo_de_tarea.:

    <?php echo get_the_term_list( $post->ID, 'tipo_de_tarea' );
    ?>

    I have various tipo_de_tareas. I would like that the function would display instead of the complete name of each taxonomy, a shorter name, that would be, for example:

    – Apuntes => AP
    – Ejercicios => EJ

    As I show in this example. At the left side, the current design, at the right, the whised:

    https://s31.postimg.org/4mh76nsa3/Captura_de_pantalla_2016_06_16_a_las_0_56_06.png

    I guess that I need to add if conditions for each tipo de tarea and the wished name, but how can I do this? I don’t know the code for this…

    Also, I would like that each one of them would have a different class to can assign a different background color for each one.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello David13_13,

    If you want to use a shorter name of your category Either you use substr function which allows you cut your string to short.So below will gives you the first 3 letters pf your category name:

    $cat_name = substr($cat_name, 0, 2)

    OR

    If you want add your shorter name to the category you can use the add term meta which will provide you the custom field for adding the custom meta.Please follow below link if you want to add the custom meta filed to your category:

    https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/

    Thanks

    Thread Starter David13_13

    (@david13_13)

    Hey!

    Thanks a lot for the reply.

    I’m going to need to use term meta, because I only can use 2 letters and if I use substr some texonomies start with the same 2 letters (Presentaciones and Proyectos Fin de Carrera…)

    So I have to create a new term short meta name using the second method that you have provided. My question is:

    How I later call the permalink, the title and the short name for generate the “a ref”. I want that the link display the short title, if you pass the mouse over it it display in a title tag the complete name and it is clickeable to go to the taxonomy page. Something like this code:

    <a href="<?php the_permalink();?>" title="<?php the_title(); ?>" class="project-item-title">
                    <?php the_title(); ?>
                </a>

    But I don’t know how to combine this with the function that I was using at the moment that is:

    <?php echo get_the_term_list( $post->ID, 'tipo_de_tarea' );
    ?>

    To call all of the necessary terms…

    And how can I solve the problem of to add a specific class for each taxonomy to can assign different background color for them?

    Thanks a lot!

    Hello David13_13,

    With reference to our solution in above comment, please create a new custom meta so as to add color class for the custom taxonomy.

    So when we add a new custom taxonomy a new field would be available in admin to add desired CSS class for specific colors.

    And in template please include following code snippet

    class="get_term_meta ( int $term_id, string $key = 'your-meta key', bool $single = false )"

    to the category HTML and also add color related css styles for those class in templates style.css
    Please try this solution.Let us know if need any further help on the same.

    Thanks

    Thread Starter David13_13

    (@david13_13)

    Thanks a lot for your answer.

    However, with your code, I didn’t get this as I said in my previous message:

    I want that the link display the short title, if you pass the mouse over it it display in a title tag the complete name and it is clickeable to go to the taxonomy page. Something like this code:

    <a href="<?php the_permalink();?>" title="<?php the_title(); ?>" class="project-item-title">
                    <?php the_title(); ?>
                </a>

    But I don’t know how to combine this with the function that I was using at the moment that is:

    <?php echo get_the_term_list( $post->ID, 'tipo_de_tarea' );
    ?>

    To call all of the necessary terms…

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Question with get_the_term_list’ is closed to new replies.