2017-07-24 32 views
1

我想獲取分配給此模板的帖子並顯示目前的內容 ,如果手動添加帖子ID,我只能顯示帖子內容。我只是想,如果後分配到這個模板來顯示內容,並顯示woocommerce頁面裏面的內容wordpress - 獲取分配給模板的帖子

<?php 
/** 
* Template Name: Sign up Page 
* 
* @package WordPress 
* @subpackage Twenty_Fourteen 
* @since Twenty Fourteen 1.0 
*/ 

echo 'this is the signup page'; 


$post = get_post(2); 
$output = apply_filters('the_content', $post->post_content); 

echo $output; 

回答

0

更新時間:

你可以嘗試使用get_page_template_slug()函數來檢查,如果當前頁面使用特定的模板,如下所示:

while (have_posts()) : the_post(); 

    $current_template = get_page_template_slug(get_the_ID()); 

    if ($current_template == 'signup.php') { 
     the_content(); 
    } 

    endwhile; 
+0

是的,我很清楚這一點,這對我正在嘗試做的事不起作用。該帖子正在woocommerce頁面內顯示 – brody

+0

更新了答案。 – user8230352