[英]Fatal error: Call to undefined function get_post()
我是 wordpress 的新手,我正在尝试创建我的第一个网站,我有一个带有 about 链接的 index.php 页面,它将从 wordpress 仪表板内创建的页面(帖子)获取关于作者的内容,名称为 about。 我正在为 poups 使用magnific popup插件。我有 about.php,其中包含这样的关于页面的内容
关于.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>
页脚.php
$('.text-ajax-popup').magnificPopup({
type: 'ajax',
alignTop: true,
overflowY: 'scroll'
});
单击链接后出现此错误
致命错误:调用未定义的 function get_post()
我可以在 about.php 中包含文件吗? 问题是什么?
您没有加载WordPress。
您需要构建主题,而不是将PHP文件放在根目录中。 WordPress将设置环境,然后加载您可以使用的主题制作功能(如get_post()
,而无需在创建的每个PHP文件中包含核心文件。
看一下如何构建默认主题,以更好地理解所涉及的主题。
我认为您需要在 PHP 文件中要求“wp-config.php”。
require_once "wp-config.php";
get_post()不是PHP方法。
在下一页上使用:
function get_post($var){
return mysql_real_escape_string($_POST[$var]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.