0

I am creating a wp theme that gets all its data via ajax (using ajax-admin.php). Now, I've set a div that would have the html of the page there (in the index.php file). My index.php is a simple one, like this:

<?php get_header(); ?>
<div id="ajaxdata"></div>
<?php get_footer(); ?>

I also setup ajax (as I said via ajax-admin.php), and it works with simple content (for example echoing there some jquery generated text or retrieving a post/page.

I have created 4 types of pages as page templates. article_1, article_2, article_3, article_4. What I want is the function that returns the page template html into a variable applied with the page data from an id. Is there a ready function on the codex or a filter/action to do that?

2
  • Assuming you're talking about pages only, there's get_page().
    – RRikesh
    Commented Dec 7, 2012 at 13:24
  • no, I have covered that, along with the page metadata. The problem is that I have a page template assigned to the page (one of the four article_x) that I also need rendered, have the result into a php variable and then echo it to the ajax mechanism.
    – Panagiotis
    Commented Dec 7, 2012 at 13:29

1 Answer 1

0

As it seems, it's an easier way, using get_template_part and some php magic. What you do is get the page name from post_metadata filter the filename without the extension and add it to get_template_part. Of course all your data must conform a predefined variable (or just pass the id to the template) because you have to use a global $post or a global $ID on the page template to retrieve that variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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