Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently making a worpress theme. In the loop I want to have two "post-entry" divs, one that's small that goes next to my post thumb, and one for without the thumb.

I know that I need to do a <?php if which I've done, but I seem to have messed up somewhere and I can't see how. I have set my loop in a query_posts, but still it's not functioning properly. Here is the code I'm using if it helps make sense:

<!-- Start the Loop. -->
<?php query_posts();
if (have_posts()) : while (have_posts()) : the_post(); ?>

<!--Begin Post-->
<div class="post">
<?php if ( has_post_thumbnail()) { ?>

<div class="post-thumb">
    <?php the_post_thumbnail(); ?>
</div>
<div class="post-entry-1">

<? } else { ?>

<!--Begin Post Entry-->
<div class="post-entry-2">
<?php } ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="post-meta"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted <?php the_time('F jS, Y') ?> <?php _e('in'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></div>
<?php the_excerpt(); ?>
</div>
<!--End Post Entry-->

</div>

</div>
<!--End Post-->

<div class="clear"></div>
<?php endwhile; ?>

<?php if (function_exists('wp_pagenavi')) { ?><?php wp_pagenavi(); ?>
<?php } else { ?>
<div class="left"><?php next_posts_link('&laquo; Older Entries') ?></div>
<div class="right"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
<?php } ?>

<?php else : ?>
<h3>Not Found</h3>
<p>Sorry, but nothing matched your search criteria. Please try again with some different keywords.</p>

<?php endif; wp_reset_query(); ?>
<!-- REALLY stop The Loop. -->

Any suggestions will be greatly appreciated, as I have been stuck on this for a few days now.

share|improve this question
    
Could you please add your desired HTML markup? I am not sure what is the issue with your current code. –  Rarst Sep 20 '10 at 9:00
    
What isn't working? What appears on the screen? It isn't clear what the problem is. –  kevtrout Sep 20 '10 at 13:06
    
Sorry I tried to add all the code I've used but it wouldn't let me. What i'm trying to do is, if a post has an image for it to generate a post thumbnail as i'm using the_excerpt() on my index page. For the posts that have a thumbnail, i'm trying to get the "post-entry-1 to go next to it. But if there isn't a thumb then post entry 2 is used instead. I'm sorry if this doesn't make sense. –  Antony Sep 20 '10 at 13:42
    
Does the post thumbnail appear if the post has an image attached? –  kevtrout Sep 20 '10 at 17:04

2 Answers 2

Something like this?..

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

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

        <?php if ( has_post_thumbnail()) { ?>

          <div class="post-thumb">
            <?php the_post_thumbnail(); ?>
          </div>
          <div class="post-entry-1">
              <?php the_excerpt(); ?>
          </div>

        <? } else { ?>

          <div class="post-entry-2">
              <?php the_excerpt(); ?>
          </div>

        <?php } ?>

    </div>

    <?php endwhile; ?>

<?php else: ?>

    <p class="no-data">
        <?php _e( 'Apologies, but no results were found.' ); ?>
    </p>

<?php endif; ?>
share|improve this answer
    
Ah thank you Rarst that's basically what i'm doing but when, I view it in a browser. The posts seem to go out side of the wrapper, for some reason? –  Antony Sep 20 '10 at 15:23
    
Is your resulting markup correct? Firebug is staple tool to deal with that if you need one. If markup is fine then it is probably CSS issue, again Firebug rocks for that as well. –  Rarst Sep 20 '10 at 15:36
    
Sorry Rarst how do you mean markup? Do you mean is everthing where it should etc, in correct divs and so on? –  Antony Sep 20 '10 at 15:49
    
Yes. Is resulting HTML output what you want it to be? Then wrong looks is issue with presentation (CSS) and not markup (HTML). –  Rarst Sep 20 '10 at 16:12
    
I think it seems to be the markup but i'm not sure, i'll see if I can get a presentation on the internet. –  Antony Sep 20 '10 at 16:25

One problem you may be having is that you have included an extra </div>

<!--Begin Post Entry-->
<div class="post-entry-2">
//your code
</div>
<!--End Post Entry-->

</div><!--End Post-->

</div><!--this appears to be extra-->

Try fixing that and see what happens. Your loop seems to be fine, just that posts are being displayed outside of your wrapper.

The error you are receiving is pointing to the fact that you haven't supplied any arguments to query_posts. Why are you using query_posts if you aren't supplying any arguments. This function is only used when you intend to modify the default WP query.

share|improve this answer
    
Thank you so very much kevtrout, you have saved my day :) it's ok now. I just tried on localhost and it's all ok, thank you for your help it was greatly appreciated it really was. –  Antony Sep 20 '10 at 18:35
    
Glad your problem has been solved. –  kevtrout Sep 20 '10 at 19:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.