WordPress:将一页的内容包含在另一页中 [英] Wordpress: include content of one page in another

查看:102
本文介绍了WordPress:将一页的内容包含在另一页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I include the page content of one or more page in another page?

例如我有 pageA pageB pageC 我想将这些页面的内容包含在 pageX

ex. I have pageA, pageB and pageC and I want to include the contents of these pages in pageX

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

is there a wordpress function that loads the post of a specified page/post?
like show_post("pageA")??

推荐答案

您好 @dany :

WordPress核心本身没有show_post()函数,但是编写起来非常容易:

There is not a show_post() function per se in WordPress core but it is extremely easy to write:

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

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

Note that this would be called with the page's path, i.e.:

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

当然,在将来WordPress核心添加同名功能的情况下,我可能不会像show_post()这样通用地命名功能.不过您的选择.

Of course I probably wouldn't name a function as generically as show_post() in case WordPress core adds a same-named function in the future. Your choice though.

而且,因为我知道他非常好,所以对 @kevtrout 也毫不留情,请考虑在StackOverflow的姊妹网站

Also, and no slight meant to @kevtrout because I know he is very good, consider posting your WordPress questions on StackOverflow's sister site WordPress Answers in the future. There's a much higher percentage of WordPress enthusiasts answering questions over there.

希望这会有所帮助.

-迈克

这篇关于WordPress:将一页的内容包含在另一页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆