Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

archive/category/tag pages incorrectly display posts WordPress

Hello,
I'm having a problem with my archive.php
When selecting a tag or category the site displays the various posts but they are not within the sites layout and jumbled throughout the page including into the sidebar.
Only the first post is within the template/layout. The frontpage of the site is okay and also includes <div id="content"> <div class="postarea">.

<?php get_header(); ?>

<div id="content">
<div class="postarea">
<?php if (have_posts()) : ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

<?php /* If this is a category archive */ if (is_category()) { ?>
<h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>

<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>

<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h2>Archive for <?php the_time('F jS, Y'); ?></h2>

<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h2>Archive for <?php the_time('F, Y'); ?></h2>

<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>

<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h2 class="pagetitle">Author Archive</h2>

<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<h2 class="pagetitle">Blog Archives</h2>

<?php } ?>
<?php while (have_posts()) : the_post(); ?>

<div class="posttitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>

<div class="entry">
<?php the_content();?>
</div>

<div class="postmetadata">
<div id="category"><?php the_category(' ') ?></div>
<div id="datemeta"><?php the_time('jS F, Y') ?></div>
<div id="readmore"><a href="<?php the_permalink() ?>" >download links</a></div><div class="clear"></div>
</div>

</div>

<?php endwhile; ?>

<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

<?php else : ?>

<h2>Not Found</h2>

<?php endif; ?>

</div>
<?php get_sidebar(); ?>

<div class="clear"></div>

</div>
<?php get_footer(); ?>

Answers (2)

2012-08-23

Arnav Joy answers:

can you show me the url of your site


Arnav Joy comments:

try this

<?php get_header(); ?>



<div id="content">

<div class="postarea">

<?php if (have_posts()) : ?>







<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>



<?php /* If this is a category archive */ if (is_category()) { ?>

<h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>



<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>

<h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>



<?php /* If this is a daily archive */ } elseif (is_day()) { ?>

<h2>Archive for <?php the_time('F jS, Y'); ?></h2>



<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>

<h2>Archive for <?php the_time('F, Y'); ?></h2>



<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>

<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>



<?php /* If this is an author archive */ } elseif (is_author()) { ?>

<h2 class="pagetitle">Author Archive</h2>



<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>

<h2 class="pagetitle">Blog Archives</h2>



<?php } ?>

<?php while (have_posts()) : the_post(); ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

<div class="posttitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>



<div class="entry">

<?php the_content();?>

</div>



<div class="postmetadata">

<div id="category"><?php the_category(' ') ?></div>

<div id="datemeta"><?php the_time('jS F, Y') ?></div>

<div id="readmore"><a href="<?php the_permalink() ?>" >download links</a></div><div class="clear"></div>

</div>



</div>



<?php endwhile; ?>



<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>



<?php else : ?>



<h2>Not Found</h2>



<?php endif; ?>



</div>

<?php get_sidebar(); ?>



<div class="clear"></div>



</div>

<?php get_footer(); ?>


Arnav Joy comments:

or try this

<?php get_header(); ?>



<div id="content">

<div class="postarea">

<?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

<?php /* If this is a category archive */ if (is_category()) { ?>
<h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>

<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>

<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h2>Archive for <?php the_time('F jS, Y'); ?></h2>

<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h2>Archive for <?php the_time('F, Y'); ?></h2>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h2 class="pagetitle">Author Archive</h2>
<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<h2 class="pagetitle">Blog Archives</h2>

<?php } ?>

<?php while (have_posts()) : the_post(); ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

<div class="posttitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>



<div class="entry">

<?php the_content();?>

</div>



<div class="postmetadata">

<div id="category"><?php the_category(' ') ?></div>

<div id="datemeta"><?php the_time('jS F, Y') ?></div>

<div id="readmore"><a href="<?php the_permalink() ?>" >download links</a></div><div class="clear"></div>

</div>



</div>



<?php endwhile; ?>



<?php //include (TEMPLATEPATH . '/inc/nav.php' ); ?>



<?php else : ?>



<h2>Not Found</h2>



<?php endif; ?>



</div>





<div class="clear"></div>



</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>


Arnav Joy comments:

see this line , this is out of while loop , so --- id="post-<?php the_ID(); ?>" -- will not be dynamic

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

2012-08-23

Daniele Raimondi answers:

You are closing the container <div> INSIDE the loop. Just move the last div outside the loop, ie, after <?php endwhile; ?>.


ajay300 comments:

That was it Daniele! Working fine now when selecting tags/categories etc.
Seems like it was a simple mistake by the creator from whom I purchased the template.

Strange that the </div> is before endwhile on the mainpage template and working fine.

New code
<?php get_header(); ?>

<div id="content">
<div class="postarea">
<?php if (have_posts()) : ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

<?php /* If this is a category archive */ if (is_category()) { ?>
<h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>

<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>

<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h2>Archive for <?php the_time('F jS, Y'); ?></h2>

<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h2>Archive for <?php the_time('F, Y'); ?></h2>

<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>

<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h2 class="pagetitle">Author Archive</h2>

<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<h2 class="pagetitle">Blog Archives</h2>

<?php } ?>
<?php while (have_posts()) : the_post(); ?>

<div class="posttitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>

<div class="entry">
<?php the_content();?>
</div>

<div class="postmetadata">
<div id="category"><?php the_category(' ') ?></div>
<div id="datemeta"><?php the_time('jS F, Y') ?></div>
<div id="readmore"><a href="<?php the_permalink() ?>" >download links</a></div><div class="clear"></div>
</div>



<?php endwhile; ?>
</div>

<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

<?php else : ?>

<h2>Not Found</h2>

<?php endif; ?>

</div>
<?php get_sidebar(); ?>

<div class="clear"></div>

</div>
<?php get_footer(); ?>


Daniele Raimondi comments:

Probably on the main page template the opening tag for that div is also in the loop, after <?php while (have_posts()) : the_post(); ?> while in archive page it's located outside.


ajay300 comments:

Oh okay,
Yes your correct about the difference between the two templates.

Thanks for correcting my problem Daniele and this is the answer I'm going to use for the site.