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 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('&nbsp;') ?></div>
                <div class="previous"><?php next_posts_link('&nbsp;') ?></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?

share|improve this question
    
+1 for staying up to date. –  kaiser Oct 18 '12 at 0:07
    
ha! thanks blush –  Kristina Childs Oct 18 '12 at 16:25

1 Answer 1

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:

  • Query
  • Templates
  • Post Thumbnails & featured images

The query

Nowadays, we're using get_posts() or new WP_Query for such cases, where you need to do another (manual) query aside from WordPress' default query.

So you'd call:

$wpse69629_query = new WP_Query( array(
    'cat'   => 8
   ,'paged' => get_query_var('paged') ? get_query_var('paged') : 1;
) );
if ( $wpse69629_query->have_posts() )
{
    while ( $wpse69629_query->have_posts() )
    {
        $wpse69629_query->the_post();

        // do stuff
    }
}

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.

enter image description here

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:

function wpse69629_feat_img_size()
{
    add_theme_support( 'post-thumbnails' ); 

    set_post_thumbnail_size( 50, 50 );
}
add_action( 'after_setup_theme', 'wpse69629_feat_img_size' );

You can then call it like this in the template:

<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
share|improve this answer
    
Wow, thank you for taking the time to write such a detailed answer. I suppose I should expand on my post, though. I have written and maintained current themes so am [fairly] familiar with new features. I'm a designer tho, not a developer, so some of this comes easier than others (and yes, I need to get those thumbnails changed cause that script is heavy on my server). The page is currently set up as a custom template, so the slug matches the category name - in this case plasmodium.net/podcasts. so are you saying I use the loop for the_content() and query for the category list? –  Kristina Childs Oct 18 '12 at 16:52
    
but the page content is managed in the actual pages. not a post. so if i do that how do i link the page content to the category page? sorry if i'm missing something. My pages: About, Contact, Podcast are about.php, contact.php and podcast.php with page templates for that content, but they also display queried data... or are you saying that i should have podcast.php and category-8.php as two documents, with the_content() in podcast.php and the loop structure in category-8.php? i'm feeling very dumb right now. thanks so much for helping –  Kristina Childs Oct 18 '12 at 17:56
    
but there isn't one master style for them. all the categories have different styles associated with them and will display different sidebars. can you still use one master category page for this and still have variable styles/content and pretty permalinks to display the slug? –  Kristina Childs Oct 18 '12 at 18:14
    
Please read into the Codex on Templates and Hierarchy. The comments are to clarify - not to teach basics. Thanks. And please clean up your comments. –  kaiser Oct 18 '12 at 18:17
    
Sorry I don't understand. I never expected a lesson from you, I was just asking for clarification because you're answer didn't make sense. It just sounded backwards. Everyone has a different thought process. Mine is visual. I will enlist a friend for help. Most of the codex may as well be written in Klingon. –  Kristina Childs Oct 18 '12 at 22:23

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.