2017-03-17 107 views
0

我正在使用OptionTree for WordPress選項面板,我正在獲取頁面ID,並使用該頁面ID來填充頁面的內容到另一頁面。這裏是我的代碼:如何在WordPress中將頁面內容填充到另一個頁面

<?php 
$test_input = ot_get_option('for_myapp_features'); 
?> 
<?php $the_query = new WP_Query('page_id=$test_input'); ?> 
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> 
<?php the_title(); ?> 
<?php the_excerpt(); ?> 
<?php endwhile;?> 

任何幫助將有所幫助。

+0

你試過這個嗎? 'echo get_post_field('post_content',$ test_input);' –

+0

@RaunakGupta謝謝,獲取內容,讓我知道如何獲得標題? –

回答

1

您可以使用get_post_fieldget_the_title()得到 內容和標題。

$test_input = ot_get_option('for_myapp_features'); 

echo get_post_field('post_title', $test_input); // to get the title 
//or 
//echo get_the_title($test_input); // to get the title 
echo get_post_field('post_content', $test_input); //to get the content 

希望這有助於!

0

如果要顯示該頁面的內容,請在while循環內添加the_content()the_content()將顯示該頁面的內容。我還會添加一個查詢重置,wp_reset_query();,結束後將全局發佈數據恢復爲原始查詢。

相關問題