Я использую настраиваемый тип сообщений: FAQ, чтобы создать текущую страницу элементов часто задаваемых вопросов.
Я создал собственный шаблон: faq-template.php, чтобы отобразить элементы.
Мне нужно перехватить другие элементы в нижней части этой страницы и на разные другие страницы. (Основы генезиса.)
Проблема заключается в том, что когда я использую is_page () для условного перехвата других элементов, он терпит неудачу, но только на шаблоне пользовательской страницы, с настраиваемым циклом.
Я подробно изложил код, чтобы объяснить проблему.
Вот код шаблона:
//Custom post type loop for FAQ: function my_custom_loop() { global $post; $args = array( 'post_type' => 'faq', 'posts_per_page' => 20, 'post_status' => 'publish', 'orderby' => 'menu_order' ); echo get_the_id(); //For testing. This successfully outputs the page ID: #19 at the top of the page template in question, so I know that WordPress recognizes this page as #19. global $wp_query; $wp_query = new WP_Query( $args ); if ( have_posts() ) : do_action ('genesis_before_entry_content'); while ( have_posts() ) : the_post(); $title=get_the_title(); $content=get_the_content(); endwhile; echo do_shortcode("[accordion]"); do_action( 'genesis_after_endwhile' ); do_action ('genesis_after_entry_content'); //Hooking stuff here endif; wp_reset_query(); } add_action( 'genesis_loop', 'bmg_custom_loop' ); remove_action( 'genesis_loop', 'genesis_do_loop' ); genesis();
Вот условные обозначения и контент, которые я использую, from functions.php:
//Hook some buttons into the bottom of certain pages: add_action( 'genesis_after_entry_content', 'my_page_buttons',999); //Where to hook function my_page_buttons() { //FIRST put the buttons only on the last page of multi-page items that use <!--nextpage--> // OR if not multi-page, then put it on singular pages: global $multipage, $numpages, $page; if ( $multipage && $page == $numpages || 1 !== $multipage ) { //NEXT put it on specific pages that meet the above condition. //This is the part that fails for page ID #19 only, the FAQ page template. if ( is_page( array( //put the buttons on these pages //When I delete this conditional, the buttons appear fine on ALL pages, including #19 19, // Why does the FAQ page does not accept it's page ID #19 with is_page()? 99, 98, 13, 113, ) ) ) { //Here's the output: ?> <div class="button-row"> <a class="button" href="<?php echo get_permalink( 49 );?> ">BUTTON ONE</a> <a class="button" href="<?php echo get_permalink( 97 );?>">BUTTON TWO</a> </div> <?php } } }
Мой вопрос еще раз: почему is_page () терпит неудачу как условие для моего настраиваемого шаблона типа сообщения?
Я просмотрел несколько других связанных тем, но не нашел ответа: почему пользовательский шаблон не рассматривается как страница с is_page ()? Условный тег is_page с настраиваемым типом страницы пользовательского шаблона, как проверить is_page из functions.php?
Дох … При написании этого вопроса вдруг стало ясно, почему он не работает:
Я зацепил мои кнопки внутри цикла, и поскольку мой цикл не был одним элементом страницы, get_the_id () получал бы идентификатор каждого сообщения в цикле, а не страницу, на которой были поставлены сообщения.
Все, что мне нужно было сделать, это зацепиться за цикл:
add_action( 'genesis_after_loop', 'my_page_buttons');
Я отправляю это на случай, если у кого-то есть аналогичная проблема.