0

I'm really new to WordPress and having a problem with my page template and a sidebar loop. I made a block that displays posts in a category in the sidebar, it also displays a custom field below the title of each post and the code looks like this:

<?php $published = get_post_meta( $post->ID, 'article_Details', true ); ?>

<div id="sidebar">
  <div id="latest">
    <h2>Recent Articles</h2>
    <?php 
        $catquery = new WP_Query( 'cat=2&posts_per_page=6' ); 
        while($catquery->have_posts()) : $catquery->the_post();
    ?>
    <a class="listing" href="<?php the_permalink() ?>"><?php the_title(); ?></a>

    <p class="pubdetails"><?php echo $published[0]['publication-details']; ?></p>

    <?php endwhile; ?>

  </div></div>

It gets displayed properly on single posts, categories and homepage but for every page on the site where it should be, it breaks, only the first item in the block gets displayed without the custom field and the foooter of the site never appears.

The template I use for my pages looks like this:

<?php get_header(); ?>

<div id="main">
    <?php while (have_posts()) : the_post(); ?>

    <article <?php post_class(); ?>>

        <header class="entry-header">

            <h1 class="entry-title"><?php the_title(); ?></h1>

        </header>

        <div class="entry-content">

            <?php the_content(); ?>

        </div>

    </article>
    </div>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

I'm not sure what the issue is, I've tried changing several things to fix the code in both the page template and the sidebar template without any luck so far.

2 Answers 2

0

Well for one thing I can spot that it seems your endwhile loop is closing OUTSIDE of a stray DIV tag. Try fixing that.

0

You are basically changing the loop in the side bar and that might be affecting your loop in the main template. For your loop to remain in tact i would suggest you do some thing like this for the side bar code.

$temp = $wp_query;
<?php 
        $catquery = new WP_Query( 'cat=2&posts_per_page=6' ); 
        while($catquery->have_posts()) : $catquery->the_post();
    ?>
    <a class="listing" href="<?php the_permalink() ?>"><?php the_title(); ?></a>

    <p class="pubdetails"><?php echo $published[0]['publication-details']; ?></p>

    <?php endwhile; ?>
$wp_query = $temp;

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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