Problem: Using PHP, I would like to know if the current page is a custom post type archive, and I would like to be able to determine the name of the Content Template applied to the current page.
Solution:
Use the native WordPress function is_post_type_archive() to determine if the current page is a post type archive:
if ( is_post_type_archive( 'my-custom-post-type-slug' ) ) { // do something }
Use the wpv_filter_content_template_output filter to determine the assigned Content Template, and assign that value to a global variable. Then access the title of the Content Template post using get_the_title() since Content Templates are technically posts:
add_filter( 'wpv_filter_content_template_output', 'get_content_template_id', 99, 4 ); function get_content_template_id( $content, $template_selected, $id, $kind ) { global $current_archive_template_id; $current_archive_template_id = $template_selected; // $template_selected = current Content Template ID return $content; } // later... $content_template_title = get_the_title($current_archive_template_id);
Relevant Documentation: https://codex.wordpress.org/Function_Reference/is_post_type_archive
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_content_template_output
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Este tema contiene 3 respuestas, tiene 3 mensajes.
Última actualización por hace 7 años.
Asistido por: Christian Cox.