Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Assuming you're talking about pages only, there's get_page(). –  RRikesh Dec 7 '12 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 Dec 7 '12 at 13:29
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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