This is my code in index.php of the WordPress theme:
<div id="content">
<?php if (have_posts()) : ?>
<?php $counter = "0"; ?>
<?php while (have_posts()) : the_post(); ?>
<?php
if ($counter % 2) {
$specialprt = "";
} else {
$specialprt = "prt-right";
}
?>
<div class="partial <?php echo $specialprt; ?>" id="post-<?php the_ID(); ?>">
<div class="prt-img">
<?php echo bdw_get_images($post->the_ID, 'medium'); ?>
</div>
<div class="prt-tags">
<?php the_tags(' ', ''); ?>
</div>
<h2 class="prt-title">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="prt-small">Posted on <?php the_time('l F jS') ?> by <?php the_author() ?></span>
<p><?php the_excerpt(); ?></p>
<p><?php edit_post_link('Edit', '', ''); ?></p>
</div>
<?php $counter++; ?>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- #content -->
Problems:
- All the posts have the same image. Why?
- Page loads very slow. Why?
Can anybody give a hand of help? :)
Thanks.
UPDATE:
I have better results with this:
<div id="content">
<?php if (have_posts()) : ?>
<?php $counter = "0"; ?>
<?php while (have_posts()) : the_post(); $counter++; ?>
<?php
if ($counter % 2) {
$specialprt = "prt-right";
} else {
$specialprt = "";
}
?>
<div class="partial <?php echo $specialprt; ?>" id="post-<?php the_ID(); ?>">
<div class="prt-img">
<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
the_attachment_link( $attachment->ID , true, false, false );
}
} else {
echo "<img src=\"<?php bloginfo('stylesheet_directory'); ?>/images/no-image.jpg\" width=\"250\" height=\"155\" />";
}
?>
</div>
<div class="prt-tags">
<?php the_tags(' ', ''); ?>
</div>
<h2 class="prt-title">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="prt-small">Posted on <?php the_time('l F jS') ?> by <?php the_author() ?></span>
<p><?php the_excerpt(); ?></p>
<p><?php edit_post_link('Edit', '', ''); ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- #content -->
$postcome from?the_post();is called, as part of the Loop.