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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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)
Dieses Thema enthält 3 Antworten, hat 3 Stimmen.
Zuletzt aktualisiert von vor 7 Jahren, 1 Monat.
Assistiert von: Christian Cox.