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条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵