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'm new to WordPress so please bear with me. I have a requirement where I need to create a page that contains a lot of static and dynamic content coming from the db. What is the best approach to do this:

  1. have 'n' shortcodes for 'n' dynamic regions?
  2. have only one shortcode that builds the entire page?
  3. any other solution?
share|improve this question
    
Could you provide us with some more details? This is not enough info to me. Every site has dynamic and static content. –  RTB Aug 3 '12 at 22:43
    
I want to create the page using Wordpress HTML editor. I can easily add static content but how to add the dynamic contents that is coming from the db? I hope you got my question now? –  Pooja Aug 4 '12 at 14:09
add comment

1 Answer

Using WP's templates you can create a page with static content already in it, and just grab the dynamic parts using WP_Query class.

<h1>Static Header</h1>
<div id="dynamic_content1">
<?php 
$recentPosts = new WP_Query();
$recentPosts->query('showposts=3');
while ($recentPosts->have_posts()) : $recentPosts->the_post();
    the_content();  // Put Loop Stuff Here
endwhile;
?>
</div>
<div id="other_dynamic_content">
    <?php 
    $anotherQuery = new WP_Query();
     $anotherQuery->query('someotherquery=1');
     while ($anotherQuery->have_posts()) : $anotherQuery->the_post();
        the_content();  // Put Loop Stuff Here
     endwhile; ?>
</div>

As you can see from the example you can load multiple dynamic components into a single page.

WordPress's template schema works as follows {post-type}-{slug/id}.php

So a page with a title of about would be page-about.php. Wordpress will automatically look for that page first when you go to /about/ if it's not in your them folder it falls back to the page.php file, if it doesn't exist it falls back to index.php (which must exist for your theme to work).

Also for posts you can follow the same schema single-{post-type}.php etc. Check out the WP template Hierarchy and WP_Query class in the codex for more info, such as the query paramaters.

share|improve this answer
    
Thanks bgallagh3r for the reply. Let me try it out!!! –  Pooja Aug 4 '12 at 14:06
    
Thanks bgallagh3r. I have implemented your solution for the dynamic content! –  Pooja Aug 6 '12 at 21:40
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.