Skip Navigation

[Resuelto] Change category order and symbol

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to display taxonomy terms associated with post in hierarchical manner that means parent term display first and then child term

Solution:
This is accomplished by adding the custom shortcode to your current theme's functions.php file.

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/change-category-order-and-symbol/#post-591409

Relevant Documentation:
https://developer.wordpress.org/reference/functions/wp_list_categories/

This support ticket is created hace 7 años. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Etiquetado: 

Este tema contiene 9 respuestas, tiene 3 mensajes.

Última actualización por Charles hace 7 años.

Asistido por: Minesh.

Autor
Mensajes
#590700

Support,

I am using the category shortcode to display my posts categories. How can I change the order so that the parent category appears before the child? Also, how can I change the comma used to separate the parent from the child to a forward slash /

Screenshot: enlace oculto

Thanks,
Chuck

#590772

When you insert Taxonomies with Toolset, you use the Guided User Interface.
That GUI lets you define all details that can be defined.
If there are settings missing it means it cannot be set.

- You can change the separator by passing it in the GUI.
- It will populate the ShortCode attribute separator="your_custom_separator" with your separator and output it. HTML is allowed.
Please use only the GUI to create such ShortCodes to ensure the right syntax.

The order you can change only to ascending or descending.
I have feature requests in place so to show terms in parental hierarchy instead of alphabetical.
But this is not yet determined when and if to be implemented.

#591098

I was able to solve the separator issue, Thanks.

I'm not looking to change the order of the actual posts, but the order that the post categories are displayed. Right now they display "child / parent". Is it possible to have them display "parent / child"?

Thanks,
Chuck

#591187

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hi Charles,

Beda is on vacation. This is Minesh here and I'll take care of this ticket and try to help you further. I hope this is OK.

As I understand you are using shortcode [wpv-post-taxonomy] to display taxonomy attached to current post:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy

If this is correct - than there is no feature available with that shortcode to display taxonomy terms in hierarchical manner:

To organize terms in hierarchical manner, Please try to add following code to your current theme's functions.php file.

function list_hierarchical_terms($atts) {
    global $post;
     
     
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
         
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

User shortcode as:

[display_post_tax_terms_hierarchical taxonomy="vehicle-type" separator="/"]

Where:
- Replace "taxonomy" attribute value with your actual taxonomy slug
- Replace "separator" attribute value as per your requirement

#591270

Minesh,

I have updated to the following, but still no change:

// Controls category hierarchy
// =============================================================================
function list_hierarchical_terms($atts) {
    global $post;
      
      
    $taxonomy = $atts['category']; 
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
          
    }
[display_post_tax_terms_hierarchical taxonomy="category" separator=" / "]

Thanks,
Chuck

#591280

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

That is strange. Can I have problem URL and temporary access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#591292

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Could you please check now, you made correction at wrong place with the code I've provided. I've corrected that and I can see its working fine now.

function list_hierarchical_terms($atts) {
    global $post;
      
      
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
          
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');
#591331

It's working, but adding an extra separator. Screenshot: enlace oculto

Thanks,
Chuck

#591409

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Ok fine.

I've adjusted code accordingly to remove the last extra separator and now it look all good.

function list_hierarchical_terms($atts) {
    global $post;
      
      
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return rtrim(trim(wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none")),'/ ');
          
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

Could you please confirm it works at your end as well.

#591882

This works!
Thanks!