我正在使用自定义帖子类型:FAQ来创建FAQ项目的持续页面。
我创建了一个自定义模板:faq模板。php,以显示项目。
我需要将其他元素挂接到这个页面和其他各种页面的底部。(Genesis框架)
问题是,当我使用is\\u 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();
下面是我从函数中获取的条件和内容。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\\u page()作为条件失败了?
我查看了其他几个相关主题,但没有找到答案:Why is custom template not seen as page with is_page()?Conditional tag is_page with a custom post typeCustom page template how to check is_page from functions.php?