WEB Wordpress Gurus, need some help

Discussion in 'OT Technology' started by symptic, Oct 15, 2008.

  1. symptic

    symptic I run companies

    Joined:
    Oct 12, 2003
    Messages:
    13,712
    Likes Received:
    0
    Currently, the theme I'm working on is set up to display posts by order of their category.

    Code:
    <?php
    $recentPosts = new WP_Query();
    $recentPosts->query('[b]showposts=1&cat=1[/b]');
    while ($recentPosts->have_posts()) : $recentPosts->the_post();
    ?>
    I've got the homepage set up so the recent posts will be displayed in a 4x4 grid, but right now it's only displaying them by order of category. How do I change this code to specify which post (in order of date) is displayed? The bold part is the code that needs changing. I'm just not sure what terminology to put in and the Codex doesn't have it.

    i.e.:

    Code:
    1st most recent , 2nd most recent , 3rd most recent , 4th most recent 
    5th most recent , 6th most recent , 7th most recent , 8th most recent 
    9th most recent , 10th most recent , 11th most recent , 12th most recent
    13th most recent , 14th most recent , 15th most recent , 16th most recent 
     
  2. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    I think the offset parameter will do what you want. Check it out on this page
    http://codex.wordpress.org/Template_Tags/query_posts

    ie
    $recentPosts->query('showposts=4&cat=1&offset=4'); for the 2nd line
    ie $recentPosts->query('showposts=4&cat=1&offset=8'); for the 3rd line and so on

    I don't know of a way to do it without a seperate loop for each row though.
     
  3. symptic

    symptic I run companies

    Joined:
    Oct 12, 2003
    Messages:
    13,712
    Likes Received:
    0
    That's fine. Looks like that's exactly what I needed. Thanks. :bowdown:
     
  4. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    To use one query you could do something like this (untested)

    Code:
    
    <?php
    $recentPosts = new WP_Query('showposts=1&cat=1');
    
    $blocks = array(1 => '', 2 => '', 3 => '', 4 =>'');
    
    $current_block = 1;
    
    while ($recentPosts->have_posts()) : $recentPosts->the_post();
    
    $blocks[$current_block] .= "<div class='post' id='post-". the_ID() ."'>
      <h2>". the_title() ."</h2>
    	<div class='entry'>
    	  ". the_content('Read the rest of this entry &raquo;') ."
    	</div>
    
    	<p class='postmetadata'>". the_tags('Tags: ', ', ', '<br />') .
    " Posted in ". the_category(', ') ." | ". edit_post_link('Edit', '', ' | ') .
    "  ".  comments_popup_link('No Comments »', '1 Comment »', '% Comments »') ."</p>
    </div>\r\n";
    
    $current_block = ($current_block < 4) ?  $current_block + 1 : 1;
    
    endwhile;
    
    // now use the blocks in the order you want, where you want..
    echo $blocks[1].$blocks[2].$blocks[3].$blocks[4];
    
    ?>
    
    
    
     
  5. symptic

    symptic I run companies

    Joined:
    Oct 12, 2003
    Messages:
    13,712
    Likes Received:
    0
    :werd:

    I wouldn't be able to use one query since the grid is split up awkwardly. It's split in the middle by columns, with the right column displaying first and the left column displaying second.

    I got it down: http://epictee.com
     
  6. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,315
    Likes Received:
    70
    Location:
    Tasmania
    I've been meaning to figure out how to do the same thing for a site for my brother.. :bowdown:
     

Share This Page