我是wordpress的新手,我正在尝试创建我的第一个网站,我有一个带有关于链接的index.php页面,它将从wordpress仪表板中的创建页面(帖子)获取有关名称的作者内容。我正在使用magnific popup插件来获取poups ..我有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中包含文件吗?有什么问题?
答案 0 :(得分:0)
你没有加载WordPress。
您需要构建一个主题,而不是将PHP文件放在根目录中。 WordPress将设置环境,然后加载您的主题,使您可以使用get_post()
等功能,而无需在您创建的每个PHP文件中包含核心文件。
了解如何构建默认主题以更好地了解所涉及的内容。
答案 1 :(得分:-2)
get_post()不是PHP方法。
在下一页上使用:
function get_post($var){
return mysql_real_escape_string($_POST[$var]);
}