我是wordpress的新手,我正在尝试创建我的第一个网站,我有一个带有关于链接的index.php页面,它将从wordpress仪表板中创建的页面(post)中获得关于作者内容的信息。我在用镁基弹出插件做邮袋。我有about.php,它包括这样的关于页面的内容
about.php
<?php
$pageid = 2; // 2 is the id of about page/post
$about = get_post($pageid);
?>
<div id="custom-content" class="white-popup-block" style="max-width:600px; margin: 20px auto;">
<h3><?php echo $about->post_title; ?></h3>
<style>
#custom-content img {max-width: 100%;margin-bottom: 10px;}
</style>
<div class="image-container pull-left">
<img src="<?php echo get_field( "image", $pageid ); ?>">
</div>
<h4><?php echo get_field( "brief", $pageid ); ?></h4>
<p>
<?php echo get_field( "brief_lines", $pageid ); ?>
</p>
<div class="about-content">
<?php echo $about->post_content; ?>
</div>
</div>index.php
<a href="<?php echo get_template_directory_uri(); ?>/about.php" class="morelink pull-left text-ajax-popup">read more</a>footer.php
$('.text-ajax-popup').magnificPopup({
type: 'ajax',
alignTop: true,
overflowY: 'scroll'
});单击链接后,我得到了这个错误。
致命错误:调用未定义函数get_post()
我可以在about.php中包含文件吗?有什么问题吗?
发布于 2015-03-26 05:10:35
你不能加载WordPress。
您需要构建一个主题,而不是将PHP文件放在根目录中。WordPress将设置环境,然后加载您的主题,使您可以使用像get_post()这样的函数,而不必在您创建的每个PHP文件中包含核心文件。
看看默认主题是如何构建的,以便更好地理解所涉及的内容。
发布于 2022-04-05 12:39:26
我认为您需要在PHP文件中使用"wp-config.php“。
require_once "wp-config.php";发布于 2015-03-25 20:00:55
get_post()不是PHP方法。
下一页使用:
function get_post($var){
return mysql_real_escape_string($_POST[$var]);
}https://stackoverflow.com/questions/29265231
复制相似问题