• Resolved ThorHammer

    (@thorhammer)


    On my Index.php I want several loops. Each post displayed with title and a custom field related image. Each loop with five posts (title and image) in their own column. Here is the code:

    <div id="cola">
    <h3>News A:</h3>
    <?php
       $cool = new WP_Query('cat=5');
       $cool->query('showposts=5');
    while ($cool->have_posts()) : $cool->the_post();
       $post_image = get_post_meta($post->ID, 'image', $single = true);
       $post_alt = get_post_meta($post->ID, 'alt', $single = true);
    ?>
    <h2><a href="<?php the_permalink() ?>"  rel="bookmark" title="Permanent url to <?php the_title(); ?>"><?php the_title(); ?></a></h2><br />
    <?php if($post_image !== '') { ?>
    <a href="<?php the_permalink(); ?>" title="<?php if($post_alt !== '') echo $post_alt; else the_title(); ?>"><img src="<?php echo $post_image; ?>" alt="<?php if($post_alt !== '') echo $post_alt; else the_title(); ?>" style="width:250px;height:190px; " /></a>
    <?php }
    	else {
    	echo 'missing image';
    	}
    ?>
    <?php endwhile; ?>
    
    </div>

    But my index.php is just blank. Not the header. Not anything. And each QP Query object is uniqe and have posts. What is wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ThorHammer

    (@thorhammer)

    bump? ??

    $cool = new WP_Query('cat=5');
       $cool->query('showposts=5');

    i have the feeling (because i don’t have any ref links to proof it)
    that these two lines might work better condensed this way:

    $cool = new WP_Query('cat=5&posts_per_page=5');

    leaving the second line away

    (btw: ‘posts_per_page’ is new for ‘showposts’)

    further:
    get_post_meta($post->ID, 'image', $single = true); and the following line:

    in my understanding, this could be written as:
    get_post_meta($post->ID, 'image', true);

    hope some of it made sense and works ??

    Thread Starter ThorHammer

    (@thorhammer)

    Thank you alchymth – again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What is wrong with my loop or Query Object?’ is closed to new replies.