【问题标题】:How do I include processed page content in a Wordpress page?如何在 Wordpress 页面中包含已处理的页面内容?
【发布时间】:2013-06-18 10:57:51
【问题描述】:

有没有办法在另一个页面中包含一个处理过的页面?

例如,在模板中,我们写 $page_data = get_page( ... 此处的页面 ID ... );

我们希望页面内容在其模板生成内容之后

例如,当我们使用时

echo apply_filters('the_content', $page_data->post_content);

我们只获取页面内容,我们想要整个页面(包装器、页眉、页脚等)

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您可以考虑使用 iframe:

    <iframe src="http://example.com/page-B" style="border:none;width:100%;height:600px;"></iframe>
    

    page-A中显示整个page-B

    您还可以查看 wp_remote_get()wp_remote_retrieve_body() 以获取远程内容:

    $the_body = wp_remote_retrieve_body( wp_remote_get('http://example.com/page-B') );
    

    transients API 使您可以将结果缓存一些$timetolive 秒,其中:

    set_transient( 'my_page_b', $the_body, $timetolive );
    

    你可以在哪里获取它

    get_transient( 'my_page_b' );
    

    资源:

    http://codex.wordpress.org/HTTP_API

    http://codex.wordpress.org/Function_API/wp_remote_get

    http://codex.wordpress.org/Function_API/wp_remote_retrieve_body

    http://codex.wordpress.org/Transients_API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 2014-09-30
      相关资源
      最近更新 更多