Wordpress:将一个页面的内容包含在另一个页面中

Zeb*_*bra 26 php wordpress

如何将一个或多个页面的页面内容包含在另一个页面中?

恩.我有pageA,pageBpageC,我想在pageX中包含这些页面的内容

是否有一个wordpress函数加载指定页面/帖子的帖子?
喜欢show_post("pageA")??

Mik*_*kel 46

@dany:

show_post()在WordPress核心中本身没有功能,但它写起来非常容易:

function show_post($path) {
  $post = get_page_by_path($path);
  $content = apply_filters('the_content', $post->post_content);
  echo $content;
}
Run Code Online (Sandbox Code Playgroud)

请注意,这将使用页面的路径调用,即:

<?php show_post('about');  // Shows the content of the "About" page. ?>
<?php show_post('products/widget1');  // Shows content of the "Products > Widget" page. ?>
Run Code Online (Sandbox Code Playgroud)

当然,我可能不会将函数命名为一般函数,因为show_post()WordPress核心在将来添加了同名函数.不过你的选择.

另外,对于@kevtrout没有任何意义,因为我知道他非常好,考虑将来在StackOverflow的姊妹网站WordPress Answers上发布你的WordPress问题.WordPress爱好者在那里回答问题的比例要高得多.

希望这可以帮助.

-麦克风