dongnue2071
dongnue2071
2015-03-25 19:52

致命错误:调用未定义的函数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 douliang2935 6年前

    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.

    点赞 评论 复制链接分享
  • dstd2129 dstd2129 6年前

    get_post() is not a PHP method.

    Use on the next page:

    function get_post($var){
         return mysql_real_escape_string($_POST[$var]);
    }
    
    点赞 评论 复制链接分享