I just upgraded to 3.4.2 from 2.9 (i know, i know, but if it ain’t broke…) I have page templates that are (or at least were) set up to display the page content first, then start a loop of posts, like so:
<div id="content">
<div class="content-title">ABOUT THE SITE</div>
<div id="content-main">
<img src="<?php bloginfo('template_url'); ?>/images/headline.gif" />
<div class="nopad"><?php the_content(); ?></div>
</div>
<div class="content-title" style="color: #05B2A9;">POSTS BY DATE</div>
<div id="comments">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array(
'cat' => 8,
'paged' => $paged
);
query_posts($args);
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$key="main img";
$my_main_img = get_post_meta($post->ID, $key, true);
$key="thumb img";
$my_thumb_img = get_post_meta($post->ID, $key, true);
?>
<div <?php post_class() ?>>
<div class="blog-list">
<div class="blog-list-img">
<!-- do stuff -->
</div>
</div>
</div>
<?php endwhile; ?>
<?php else : endif; ?>
<div id="blog-list-more">
<div class="next"><?php previous_posts_link(' ') ?></div>
<div class="previous"><?php next_posts_link(' ') ?></div>
</div>
</div>
</div>
This worked great in 2.9 but in this new upgrade it isn’t displaying the page content. I have multiple page templates and was able to fix it on the pages that ran simple queries (like list of the blog contributors) by putting
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
before <div id="content">
, but as you can imagine on the main blog archive page this isn’t an option. (I tried just to be sure).
So how does one get the contents of the page outside the main loop? Do I have to run two loops? It seems this would be a simple enough thing but I can’t work out how. I can’t run a simple query in this page because there’s all sorts of crazy stuff going on in there. Or can I?
Updating a theme isn’t that hard. But it’s necessary to let it play nice with the current version of the core.
Here’re some notes on what you might need to do:
The query
Nowadays, we’re using
get_posts()
ornew WP_Query
for such cases, where you need to do another (manual) query aside from WordPress’ default query.So you’d call:
Template Hierarchy
As you have a query that does nothing than loading posts from a specific category, you might consider adding another template that triggers only for this category. This will save you an additional query.
Just copy your code (without the query, but with a default loop) into a new file named
category-8.php
.The post thumbnail
With (afaik) WP 2.9, post thumbnails/feat.images arrived. It just seems that this wasn’t implemented in your theme back then.
You can now grab the assigned thumbnail (featured image meta box) simply by calling
the_post_thumbnail()
in list views and()
for single views.The support for this feat. and the size will be set inside your functions php with something like that:
You can then call it like this in the template: