dongnue2071 2015-03-25 19:52
浏览 123
已采纳

致命错误:调用未定义的函数get_post()

I'm new on wordpress and I'm trying to create my first website, I have an index.php page with about link, which will get about author content from created page (post) inside wordpress dashboard with name about. I'm using magnific popup plugin for poups.. I have about.php which includes content of about page like this

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' 
});

after click on the link I got this error

Fatal error: Call to undefined function get_post()

Is there files could I include inside about.php ? what is the problem ?

  • 写回答

2条回答 默认 最新

  • douliang2935 2015-03-26 05:10
    关注

    You're not loading WordPress.

    You need to build a theme instead of putting PHP files in the root directory. WordPress will setup the environment and then load your theme making functions like get_post() available to you without you having to include core files in every PHP file you create.

    Take a look at how the default themes are built to get a better understanding of what's involved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮