• Resolved schultzy

    (@schultzy)


    I did a search and didn’t find my answer. Closest I got had someone point the the reference on the get_post tag but I don’t understand enough.

    This is what I am trying to do or the page set up.

    News Header (that’s easy)
    The newest post (1) from category 1

    Latest Short Story
    Latest story post (1) from category 2,3,4, etc

Viewing 6 replies - 1 through 6 (of 6 total)
  • Read up on The Loop and multiple loop construction:

    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/The_Loop#Multiple_Loops

    Basically you want to look into setting up two post loops, one which includes the News category only, and one which excludes it. Ask for more detail if you get lost on the doc I pointed to.

    Thread Starter schultzy

    (@schultzy)

    I took the example from the page you directed me to and came up with the following code.

    <?php $my_query = new WP_Query('category=3&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
    
    <h1>Latest Blog Entry</h1>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    			<small>By <?php the_author() ?>  | <?php the_time('F j, Y'); ?> <?php edit_post_link('(edit)'); ?></small>
    
    			<div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    			</div>
    
    			<p class="postmetadata"><?php the_tags('Tags: ', ', ', '.'); ?> Read more from <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    
    			</div>
    
      <?php endwhile; ?>
    
      <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    
    <h1>Latest Story</h1>
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    			<small>By <?php the_author() ?>  | <?php the_time('F j, Y'); ?> <?php edit_post_link('(edit)'); ?></small>
    
    			<div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    			</div>
    
    			<p class="postmetadata"><?php the_tags('Tags: ', ', ', '.'); ?> Read more from <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    
    			</div>
    
      <?php endwhile; endif; ?>

    So, it gives me a single post from category 3 and then follows with the other posts based on the default number of posts to show.

    How do I specify that I want 1 post form categories x,y,z like I did for the first part of the loop?

    Thread Starter schultzy

    (@schultzy)

    anyone have an idea?

    Have a new query where you exclude cat=3 and define the number of posts shown.

    Thread Starter schultzy

    (@schultzy)

    Ok, I think I got it. If someone could just take a look at the code and see if they see anything wrong. As far as I can tell, it works.

    <font size="5">Latest Blog Entry</font>
    <!-- begin news loop -->
    <?php $my_query = new WP_Query('category=3&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    			<small>By <?php the_author() ?>  | <?php the_time('F j, Y'); ?> <?php edit_post_link('(edit)'); ?></small>
    
    			<div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    			</div>
    
    			<p class="postmetadata"><?php the_tags('Tags: ', ', ', '.<br />'); ?> Read more from <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
    
    <?php endwhile; ?>
    <!-- end news loop -->
    
    <font size="5">Latest Story</font>
    <!-- begin story loop -->
    <?php query_posts('cat=5,25,21,26,19,10,27,29,24&showposts=1'); ?>
    <?php while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    			<small>By <?php the_author() ?>  | <?php the_time('F j, Y'); ?> <?php edit_post_link('(edit)'); ?></small>
    
    			<div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    			</div>
    
    			<p class="postmetadata"><?php the_tags('Tags: ', ', ', '.<br />'); ?> Read more from <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
    
      <?php endwhile; ?>
    <!-- end story loop -->
    Thread Starter schultzy

    (@schultzy)

    Looks like it is working, will make as resolved and if I have further issues, will address them seperate.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Two seperate post sections’ is closed to new replies.