Wrong categories displaying on homepage (Wordpress)

Discussion in 'PHP' started by Joe Crogan, Sep 2, 2009.

  1. #1
    Hi all,

    My website (magazine style) has started to do something strange -

    On my home page each post (excerpt) should have it's category listed underneath it along with how many comments. The exact same code is used on archive.php and it works perfectly.

    However, on my homepage - this is not working. Whatever category my latest post is in (e.g. - currently 'Seagull Serious') the code converts all the other posts to the same category. Similarly, If I click on the comments link of any post on my homepage it is linked to the first post. And finally, the "read the full story" on all posts are linked to the latest post as well. Again, this doesn't happen inside archives.php pages.

    I should probably stress, although they appear to be in the wrong category all the posts are still in the correct category. It is only a visual thing - where they appear to be in the wrong category. As when I check inside my Category Nav bar, all posts are where they should be.

    The following is the code for my hompage -

    The code in bold is for displaying the categories/comments and this is the same on archive.php (which works!)

    <h2>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></h2>
    <p>by <?php the_author()?></p>
    <p><?php echo strip_tags(get_the_excerpt(), ''); ?></p>
    <p><span class="continue">" href="<?php the_permalink() ?>">Read the full story</span></p>

    <h3 class="posted">Posted in <?php the_category(', ') ?><span class="comments"><?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?></span></h3>


    I got rid of all my widgets in my sidebar and nothing changed – so not them. And I replaced /public_html/wp-content/themes/gazette-dev/gazette/includes/featured.php with the original version - Didn't work.

    I hope this is all clear. If I am wording anything wrong, or you need any other code plez just shout.

    A million thankyous to anyone that can help!

    http://www.joecrogan.com
     
    Joe Crogan, Sep 2, 2009 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Post the entire homepage template file, not just the snippet. The above doesn't show the loop, which is where your problem is.
     
    Christian Little, Sep 2, 2009 IP
  3. Joe Crogan

    Joe Crogan Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for getting back to me. The following is my homepage.php - I have a nasty feeling you may not find what you are looking for here (as I don't think it has changed & used to work), if so, if you can think of any other pages I will grab them asap. Thanks so much - this prob has been driving me crazy!

    <div class="box">

    <?php
    include(TEMPLATEPATH . '/includes/version.php');

    $the_query = new WP_Query('cat=-'. $ex_feat . ',-' . $ex_vid . '&showposts=' . $showposts . '&orderby=post_date&order=desc');

    $counter = 0; $counter2 = 0;

    while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
    ?>

    <?php $counter++; $counter2++; ?>

    <div class="post <?php if ($counter == 1) { echo 'fl'; } else { echo 'fr'; $counter = 0; } ?>">

    <?php if ( get_post_meta($post->ID, 'image', true) ) { ?> <!-- DISPLAYS THE IMAGE URL SPECIFIED IN THE CUSTOM FIELD -->

    <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&amp;h=57&amp;w=100&amp;zc=1&amp;q=80" alt="<?php the_title(); ?>" class="th" />

    <?php } else { ?> <!-- DISPLAY THE DEFAULT IMAGE, IF CUSTOM FIELD HAS NOT BEEN COMPLETED -->

    <img src="<?php bloginfo('template_directory'); ?>/images/no-img-thumb.jpg" alt="" />

    <?php } ?>

    <h2><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <p><em>by <?php the_author()?></em></p>
    <p><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?></p>
    <p><span class="continue"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">Read the full story</a></span></p>

    <h3 class="posted">Posted in <?php the_category(', ') ?><span class="comments"><?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?></span></h3>

    </div><!--/post-->



    <?php if ( !($counter2 == $showposts) && ($counter == 0) ) { echo '<div class="hl-full"></div>'; ?> <div style="clear:both;"></div> <?php } ?>

    <?php endwhile; ?>

    <div class="fix" style="height:10px"></div>

    <?php $archives_page = get_option('woo_archives_page') . '/'; ?>

    <p class="ar"><a href="<?php echo "$archives_page"; ?>" class="more">See more articles in the archive</a></p>

    </div><!--/box-->
     
    Joe Crogan, Sep 2, 2009 IP
  4. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I doubt this will fix it, but let's try it as a basic fix first:

    
    <?php the_category(', ') ?>
    
    PHP:
    Change that to:

    
    <?php the_category(); ?>
    
    PHP:
    Let me know what happens.
     
    Christian Little, Sep 2, 2009 IP
  5. Joe Crogan

    Joe Crogan Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah, no good. It just lists everything horizontally instead of vertically. All the links are the same. I have left it in case u want to have a look.
     
    Joe Crogan, Sep 2, 2009 IP
  6. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Figured as much lol. Alright, let's look at the query then:

    
    $the_query = new WP_Query('cat=-'. $ex_feat . ',-' . $ex_vid . '&showposts=' . $showposts . '&orderby=post_date&order=desc');
    
    PHP:
    What is $ex_feat and $ex_vid being set to on the homepage?
     
    Christian Little, Sep 2, 2009 IP
  7. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Also - you might want to tweak your SEO plugin settings. Your homepage title is appearing is "Joe Crogan |". It should be something like "Joe Crogan | something here"
     
    Christian Little, Sep 2, 2009 IP
  8. Joe Crogan

    Joe Crogan Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have totally deleted my SEO plugin for now as it is one of my latest installments so I figured it may be to blame. I inserted a tagline "seagull" in general wordpress setting area, just to see.

    I have attached an image of my front page settings (excuse the quality - just to keep file small). You can see I choose to include all categories and NOT to use the video display. I believe that is what the code is tracking?

    Anyway, please see attached - thanks
     

    Attached Files:

    Joe Crogan, Sep 2, 2009 IP
  9. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Alright here's the problem:

    'cat=-'. $ex_feat . ',-' . $ex_vid . '
    PHP:
    What that's doing is telling wordpress to only display posts from a specific category. For some reason it's always selecting the 1 category.

    So what you need to do is fix the WP_query command. It's not working for the specific parameters. I'm not an expert at that specific function call as I usually use the built-in loop functions rather than experimenting with WP_query.

    What you can do is change it to this:

    $the_query = new WP_Query('showposts=' . $showposts . '&orderby=post_date&order=desc');
    PHP:
    That will display posts from all categories, which is a start in the right direction. I'm not sure how to modify it to exclude a specific category, but at least the above code will show all posts instead of just the specific category.
     
    Christian Little, Sep 2, 2009 IP
  10. Joe Crogan

    Joe Crogan Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It has the same result. Sorry if I didn't explain this correctly - but the homepage is showing posts from ALL categories and is functioning fine. It is only the category name display that is wrong. So all the content that is on the homepage comes from different categories, it is just that category name is getting displayed incorrectly.

    Again, sorry if I didn't make this clear

    Graeme
     
    Joe Crogan, Sep 2, 2009 IP