• Resolved surfershort

    (@surfershort)


    Hi as you can see on my site http://rollingsixes.co.uk/sixsurf/ the middle column is displaying one post from each category, i really need just the 5 most recent posts or posts from the last 30 days to show.

    Ive posted this problem in the themes support (live wire/wootheme) and i was asked to change this code in the index.php file

    $the_query = new WP_Query('showposts=1&posts_per_page=-1&cat='.$cat->cat_ID);

    to

    $the_query = new WP_Query('showposts=5&posts_per_page=-1&cat='.$cat->cat_ID);

    All this did was display 5 posts from each category making the column even longer.

    Ive seemed to to have found the correct code here http://codex.wordpress.org/Function_Reference/query_posts

    <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts in the last 30 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>

    but i have no idea how to implement it into my index.php file below.

    Any help would be greatly appreciated
    Thanks

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Make a backkup first, in case this is totally wrong! Then, change this:

    foreach ($cats as $cat) {
       $the_query = new WP_Query('showposts=1&posts_per_page=-1&cat='.$cat->cat_ID);

    to this:

    foreach (array(1) as $cat) {
       $the_query = new WP_Query('posts_per_page=5);

    and remove this line:

    <p class="category"><span><?php echo $cat->cat_name; ?></span></p>

    Thread Starter surfershort

    (@surfershort)

    Thanks man thats awesome and it even lists them in the correct date!!!but i could only get it work like this

    foreach (array(1) as $cat) {
    $the_query = new WP_Query('showposts=5&posts_per_page=-1&cat='.$cat->cat_ID);

    If i put just $the_query = new WP_Query('posts_per_page=5);it returned a syntax error.

    Is there anyway to keep the category span above the post as i have to credit the source of the story – which is the category..i tried to leave it in but its not showing the text http://rollingsixes.co.uk/sixsurf/

    Many Thanks
    Al

    The syntax error is because I left out a single quote in the WP_Query line. It should be this:

    foreach (array(1) as $cat) {
       $the_query = new WP_Query('posts_per_page=5');

    As for the category name, try altering this:

    <p class="category"><span><?php echo $cat->cat_name; ?></span></p>

    to this:

    <p class="category"><span><?php the_category(); ?></span></p>

    To get the_category() to work, you may need to add the line:

    <?php setup_postdata($post): ?>

    after your while ( $the_query->have_posts). The moderators have stripped out your code, so I can’t see it any more to be sure. Post just a few lines around the while statement so I can see it again.

    Thread Starter surfershort

    (@surfershort)

    Thanks mate nearly there…..its added the tag to the top of the post but it seems to be in a strange format, unfortunetley i cant seem to add the <?php setup_postdata($post): ?> without the syntax error.

    Excuse my ability heres the code
    Thanks Al

    $cats = get_categories('exclude='. $GLOBALS[ex_feat] . ',' . $GLOBALS[ex_vid]. ',' . $excluding );
    		foreach (array(1) as $cat) {
    			$the_query = new WP_Query('posts_per_page=5');
    		while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
    
    	?>
    
    				<?php
    
    						$show = true;
    						foreach ( $duplicated as $test) { if ( $test == $post->ID) { $show = false; } }
    
    						$count++;
    						$duplicated[$count] = $post->ID;
    
    						if ($show) {
    
    				?>
    
    				<div class="post-alt blog">	
    
    	               <p class="category"><span><?php the_category(); ?></span></p>
    	               <?php woo_get_image('image',get_option('woo_thumb_width_mid'),get_option('woo_thumb_height_mid'),'thumbnail '.$GLOBALS['align_mid']); ?>

    After seeing the code, I don’t think you need the setup_postdata.

    To change the format of the categories, just add ‘,  ‘ as a parameter as shown below:

    $cats = get_categories('exclude='. $GLOBALS[ex_feat] . ',' . $GLOBALS[ex_vid]. ',' . $excluding );
    foreach (array(1) as $cat) {
       $the_query = new WP_Query('posts_per_page=5');
       while ($the_query->have_posts()) : $the_query->the_post();
          $do_not_duplicate = $post->ID;?>
          <?php
          $show = true;
          foreach ( $duplicated as $test) { if ( $test == $post->ID) { $show = false; } }
          $count++;
          $duplicated[$count] = $post->ID;
          if ($show) {?>
             <div class="post-alt blog">
                <p class="category"><span><?php the_category(', '); ?></span></p>
                <?php woo_get_image('image',get_option('woo_thumb_width_mid'),get_option('woo_thumb_height_mid'),'thumbnail '.$GLOBALS['align_mid']); ?>
    Thread Starter surfershort

    (@surfershort)

    Hey vtxyzzy really appreciate your help and that has sorted the category text out perfect but unfortunetly its now not displaying the post images and only the 5 recent posts from one category…….

    Im happy to pay you a few bucks if you can sort it.

    Any thoughts…..?

    Many Thanks
    Al

    I am shooting in the dark here. Please post the original code in the pastebin so I can see the whole thing.

    Thanks for the offer of payment, but I still would not have the theme to work with. I’ll be glad to help once I can see the code.

    As far as the 5 recent posts from one category is concerned, are you sure you have more recent posts in a different category? Looks like all those shown on your site are from today.

    Thread Starter surfershort

    (@surfershort)

    Yes your right the latest posts are all from the same cat!! ok ive posted the index.php code here

    Cheers again
    Al

    Thread Starter surfershort

    (@surfershort)

    Yo vtxyzzy you are a legend thanks so much!!!! its all working now mate.

    I owe you a pint if you are ever in Cornwall.

    Cheers
    Al

    You are welcome! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

    And, if you ever come to Louisville, KY, I’ll spring for the bourbon!

    Thread Starter surfershort

    (@surfershort)

    Hi again ive noticed the recent posts in the middle column are not displaying the thumbnail image correctly….any idea why….?

    Im sure its something to do with the custom fields….

    Cheers
    Alec

    I can’t tell why it is happening, but the code for displaying the images is messed up. Looks like part of it is duplicated:

    This is what I see in the source:

    <a alt="" href="http://rollingsixes.co.uk/sixsurf/?p=5016" ><img src="<img src="http://rollingsixes.co.uk/sixsurf/wp-content/uploads/2010/06/9a5e8b40ccguide1.jpg.jpg" />" alt="" width="198" height="100" class="woo-image thumbnail alignleft" /></a>

    It should be this:

    <a href="http://rollingsixes.co.uk/sixsurf/?p=5016" ><img src="http://rollingsixes.co.uk/sixsurf/wp-content/uploads/2010/06/9a5e8b40ccguide1.jpg" alt="" width="198" height="100" class="woo-image thumbnail alignleft" /></a>

    It may be something in the way you uploaded or inserted the images.

    Thread Starter surfershort

    (@surfershort)

    Its strange that the posts that are already in the database are displaying correctly… when i run the post generator now the same posts wont display the thumbnail correct…could i send you my login details to have a look in the admin panel?

    Thanks
    Al

    Sorry, I prefer not to do that.

    Thread Starter surfershort

    (@surfershort)

    All sorted i needed to add a custom field into the template

    Custom Field: image

    Custom Field Value: %image_path%

    Cheers
    Al

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Posts on home page’ is closed to new replies.