Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this code trying to sort by a specific category. I keeps saying it has an unexpected $end on line 39. What did I do wrong in the code. I've been playing with it and reading the codex for a while and can't figure it out.

<?php get_header(); ?>
<div id="container">
    <div id="content">

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

  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
  <?php /* If this is a category archive */ if (is_category('5')) { ?>
      <h1 class="pagetitle"><?php _e('Archive for the', 'default'); ?> &#8216;<?    php single_cat_title(); ?>&#8217; <?php _e('category', 'default'); ?></h1>
      <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class(archives-page) ?>>
        <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"   rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <small class="meta"><?php the_time(__('F jS, Y','default')); ?> <?php edit_post_link(__( 'Edit', 'default' ), ' | ', ''); ?></small>

        <div class="entry">
            <?php the_content((__( '&raquo; Read more: ', 'default')) . the_title('', '', false)); ?>
        </div>

        <div class="postmetadata clearfix">
    <p class="commentslink alignright">
      <?php comments_popup_link( __( 'No comments', 'default' ), __( '1 comment', 'default' ), __( '% comments', 'default' )); ?> &#187;
    </p>
          <p class="categories">
      <?php _e('Posted in ', 'default' ); the_category(', '); ?>
    </p>
          <?php the_tags( '<p class="tags">Tags: ', ' ', '</p>'); ?>
  </div>
    </div>

    <?php endwhile; ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>
share|improve this question
You have two while( have_posts() ) lines, when you should have only one. – t31os Jul 30 '11 at 9:22

closed as too localized by toscho Jul 6 '12 at 20:15

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

I've found one endif; missing & one unclosed bracket.

Fixed version:

<?php get_header(); ?>
<div id="container">
    <div id="content">

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

  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
  <?php /* If this is a category archive */ if (is_category('5')) ?>
      <h1 class="pagetitle"><?php _e('Archive for the', 'default'); ?> &#8216;<?php single_cat_title(); ?>&#8217; <?php _e('category', 'default'); ?></h1>
      <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class(archives-page) ?>>
        <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"   rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <small class="meta"><?php the_time(__('F jS, Y','default')); ?> <?php edit_post_link(__( 'Edit', 'default' ), ' | ', ''); ?></small>

        <div class="entry">
            <?php the_content((__( '&raquo; Read more: ', 'default')) . the_title('', '', false)); ?>
        </div>

        <div class="postmetadata clearfix">
    <p class="commentslink alignright">
      <?php comments_popup_link( __( 'No comments', 'default' ), __( '1 comment', 'default' ), __( '% comments', 'default' )); ?> &#187;
    </p>
          <p class="categories">
      <?php _e('Posted in ', 'default' ); the_category(', '); ?>
    </p>
          <?php the_tags( '<p class="tags">Tags: ', ' ', '</p>'); ?>
  </div>
    </div>

    <?php endwhile; endif;  ?>
    <?php endwhile; endif; ?> 

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

Does it work now?

share|improve this answer
Now it repeats Archive for the ‘’ category endlessly. So for some reason it is skipping the the_content action which has something to do with the loop not closing/ending properly. I'll keep looking, thanks for the help. This is an improvement. – JackMcE Jul 30 '11 at 2:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.