Viewing 4 replies - 1 through 4 (of 4 total)
  • The query_posts() article discusses various time related arguments and has several example.

    Good discussion on multiple loops for things:
    https://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

    Note query_posts and get_posts share the same arguments

    Thread Starter central101

    (@central101)

    Hello MichaelH,

    I’ve looked at the examples that are in those links and have also done some of my own research and I my head is just hurting.

    So here’s the scoop. I am trying to edit a wordpress template and make two seperate tables with two different loops.

    Here’s what I would like it to look like.
    https://i28.photobucket.com/albums/c247/joduby/demo.gif
    For now it only displayed in one table. If I could get someone to edit the code so there are two seperate tables I would be able to do everything else on my own.

    Thanks in advance. Theres is some unless in code below that I will remove once I get it working properly.

    Here’s the code for the main index.

    <?php get_header(); ?>

    <div class=”content”>
    <ul class=”nav”>
    <li<?php if ( is_home() ) { echo ” class=\”current-cat\””; } ?>>” title=”Homepage” >Recently Added

    • <div class=”clear”></div>
    • <?php
      if (is_category()) {
      $cat_id = get_query_var(‘cat’);
      $cats = wp_list_categories(‘echo=0&title_li=&show_count=0&use_desc_for_title=0&child_of=’.$cat_id);
      if ( $cats != “

    • No categories
    • “) {
      ?>
      <div class=”subnav”>

      <?php wp_list_categories(‘title_li=&orderby=name&show_count=0&use_desc_for_title=0&child_of=’.$cat_id); ?>

    </div>
    <?php } //if $cats != no categories ?>
    <?php } //if is category ?>
    <div class=”main”>
    <div class=”listing”>
    <div class=”head”>
    <span class=”name”>Item Name</span>
    <span class=”price”>Price</span>
    <span class=”location”>Location</span>
    <span class=”date”>Post Date</span>
    <div class=”clear”></div>
    </div>
    <div class=”list”>
    <?php $i = 1; ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ($i % 2 == 0) { $alt = ” class=\”alt\””; } else { $alt = ” class=\”no\””; } ?>
    <div<?php echo $alt; ?>>
    ” title=”<?php the_title(); ?>”>
    <span class=”image”>
    <?php if ( get_option(‘main_page_img’) == “yes” ) { ?>
    <div class=”main_page_img” style=”background: #FFF url(<?php echo get_bloginfo(‘template_url’).”/img_resize.php?width=50&height=50&url=”;?><?php cp_one_img(get_the_content()); ?>) center no-repeat”></div>
    <?php } else {
    $ii = 1;
    foreach((get_the_category()) as $category) {
    if ($ii == “1”) {
    echo “<img src=\””.get_bloginfo(‘template_url’).”/images/category-icons/”.get_option(“cat$category->cat_ID”).”.png\” alt=\”$category->cat_name\” title=\”$category->cat_name\” />”;
    $ii++;
    }
    }
    }
    ?>
    </span>
    <span class=”name”><?php if ( strlen(get_the_title()) > 30 ) { echo substr(get_the_title(), 0, 30).”…”; } else { the_title(); } ?></span>
    <span class=”price”><?php echo get_option(‘currency’); ?><?php cp_price(get_the_content()); ?></span>
    <span class=”location”><?php cp_location_single(get_the_content()); ?></span>
    <span class=”date”><?php the_time(‘F jS, Y’); ?></span>

    <div class=”clear”></div>
    </div>
    <?php $i++; unset($alt); ?>
    <?php endwhile; ?>
    <div class=”navigation1″>
    <div class=”navigation2″>
    <div class=”alignleft”>
    <?php next_posts_link(‘<img src=”‘.get_bloginfo(‘template_url’).’/images/back.jpg” alt=”Older Entries” />’) ?>
    </div>
    <div class=”alignright”>
    <?php previous_posts_link(‘<img src=”‘.get_bloginfo(‘template_url’).’/images/next.jpg” alt=”Newer Entries” />’) ?>
    </div>
    </div>
    <div style=”clear:both;”></div>
    </div>
    <div style=”clear:both;”></div>

    <?php endif; ?>

    The code needs alot of work, you have lots of opening elements and very little closing….

    <li> has no closing…
    <ul> has no closing…

    Lots of <div> have no closing tags also..

    Fix your HTML first, then post back, it’s too confusing right now to determine how the above HTML ‘should’ look…

    That’s only stratching the surface to, there’s quite a few places where you’re incorrectly nesting or switching in and out of PHP…

    I did make a start tidying, but like i said it really needs the HTML fixed. Without knowing it’s my best guess at how the code should be… this is where i got to before posting, anyone else of course welcome to expand on what i started, though i would suggest you work at getting the HTML correctly formatted and close off any tags that need closing first…

    <?php get_header(); ?>
    
    <div class="content">
      <ul class="nav">
        <li <?php if ( is_home() ) { echo 'class="current-cat"'; } ?>>Recently Added #
          <div class="clear"></div>
        </li>
      </ul>
      <?php
      if (is_category()) {
        $cat_id = get_query_var('cat');
        $cats = wp_list_categories('echo=0&title_li=&show_count=0&use_desc_for_title=0&child_of='.$cat_id);
        if ( $cats != "# No categories") {
          ?>
          <div class="subnav">
            <?php wp_list_categories('title_li=&orderby=name&show_count=0&use_desc_for_title=0&child_of='.$cat_id); ?>
          </div>
          <?php
        } //if $cats != no categories
      } //if is category
      ?>
      <div class="main">
        <div class="listing">
          <div class="head">
            <span class="name">Item Name</span>
            <span class="price">Price</span>
            <span class="location">Location</span>
            <span class="date">Post Date</span>
            <div class="clear"></div>
          </div>
        <div class="list">
          <?php
          $i = 1;
          if (have_posts()) :
          while (have_posts()) : the_post();
          if ($i % 2 == 0) {
            $alt = 'class="alt"';
          } else {
            $alt = 'class="no"';
          }
          ?>
          <div <?php echo $alt; ?>>
          <?php the_title(); ?>
          <span class="image">
          <?php
          if ( get_option('main_page_img') == "yes" ) { ?>
          <div class="main_page_img" style="background: #FFF url(<?php echo get_bloginfo('template_url')."/img_resize.php?width=50&height=50&url=";?>
          <?php cp_one_img(get_the_content()); ?>) center no-repeat">
          </div>
          <?php
          } else {
          $ii = 1;
            foreach((get_the_category()) as $category) {
              if ($ii == "1") {
                echo "<img src=\"".get_bloginfo('template_url')."/images/category-icons/".get_option("cat$category->cat_ID").".png\" alt=\"$category->cat_name\" title=\"$category->cat_name\" />";
                $ii++;
              }
            }
          }
          ?>
          </span>
          <span class="name"><?php if ( strlen(get_the_title()) > 30 ) { echo substr(get_the_title(), 0, 30)."..."; } else { the_title(); } ?></span>
          <span class="price"><?php echo get_option('currency'); ?><?php cp_price(get_the_content()); ?></span>
          <span class="location"><?php cp_location_single(get_the_content()); ?></span>
          <span class="date"><?php the_time('F jS, Y'); ?></span>
    
          <div class="clear"></div>
        </div>
      <?php $i++; unset($alt); ?>
      <?php endwhile; ?>
      <div class="navigation1">
        <div class="navigation2">
          <div class="alignleft">
          <?php next_posts_link('<img src="'.get_bloginfo('template_url').'/images/back.jpg" alt="Older Entries" />') ?>
          </div>
          <div class="alignright">
          <?php previous_posts_link('<img src="'.get_bloginfo('template_url').'/images/next.jpg" alt="Newer Entries" />') ?>
          </div>
        </div>
    
        <div style="clear:both;"></div>
    
      </div>
    
    <div style="clear:both;"></div>
    
    <?php endif; ?>
    Thread Starter central101

    (@central101)

    I sent you a message at your website t31os.co.uk

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Retrieve posts belonging to a certain time period??’ is closed to new replies.