0

我正在为 WordPress 选项面板使用 OptionTree,我正在获取页面 ID,并使用该页面 ID 将页面的内容填充到另一个页面。这是我的代码:

<?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;?>

任何帮助都会有所帮助。

4

2 回答 2

1

您可以使用get_post_fieldandget_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

希望这可以帮助!

于 2017-03-17T11:52:58.627 回答
0

如果要显示该页面的内容, the_content()请在 while 循环中添加。the_content()将显示页面的内容。我还会wp_reset_query();在 endwhile 之后添加一个查询重置,以将全局发布数据恢复到原始查询。

于 2017-03-17T06:53:34.963 回答