1

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:

<?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>

and in index.php

<a href="<?php echo get_template_directory_uri(); ?>/about.php" class="morelink pull-left text-ajax-popup">read more</a>

and in the 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

The problem is that about.php is not a recognized file by WordPress and won't load any of the actual WordPress functions. <?php wp_header(); ?> in your themes header.php file actually loads most the WordPress functionality that you're used to using. Since you're not calling either get_header() OR wp_header() in your about.php file you don't actually have access to any of the WordPress functionality. One solution to this would be to include a core WordPress file at the top of your post which will give you this kind of access:

This file: require('/wp-blog-header.php');

The required file is located in the root of WordPress, same place as wp-config.php - I believe this will load what you need.

Here's a list of Recognized Template Files.

What should do though...

Is find a way to use the build in wp_ajax functionality to get your page and bring it back. Then there's no extra file, no need to require wp-blog-header.php and it hook / function would be conveniently located in your themes functions.php file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.