【发布时间】:2014-09-29 18:53:43
【问题描述】:
在网上和这里做了很多搜索,但找不到答案,尽管我知道这可能非常简单。我错过了一些东西......
我正在尝试将 Wordpress PAGE(由 Wordpress 插件 All In One Event Calendar 自动创建的页面)的内容嵌入到我网站上的页面中。
(注意:我已经确认“page”和“post”是同一个东西……)
当我访问 Wordpress codex 时,我得到了这个页面:http://codex.wordpress.org/Function_Reference/get_page,它告诉我 get_page 函数已被弃用,并将我发送到 codex 的“get post”页面。
我尝试嵌入的 wordpress PAGE(不是 POST)的 URL 看起来像 http://xxxxxx.com/test/blog/?page_id=4。
我的网站顶部有以下代码...
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('/home3/xxxxxx/public_html/xxxxxx/xxxxxx/blog/wp-load.php');
?>
(注意:已确认 wp-load 有效... wp-blog-header.php 无效。谢谢,培根!)
并创建了循环:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$id = 4;
$p = get_post($id);
echo apply_filters('the_content', $p->post_content);
endwhile; else :
_e( 'Sorry, no posts matched your criteria.' );
endif; ?>
我用来尝试嵌入页面内容的代码是:
<?php
$id = 4;
$p = get_post($id);
echo apply_filters('the_content', $p->post_content);
?>
它似乎不起作用。它返回错误消息(对不起,没有帖子符合您的条件。)但是有一个 ID 为 4 的帖子(页面)。
我错过了什么?
请保持温和,并提前感谢您提供的任何帮助。
【问题讨论】: