WordPress.org

Ready to get started?Download WordPress

Forums

Help with The Loop (5 posts)

  1. dbUNIT16
    Member
    Posted 6 years ago #

    Hello,

    I am trying to run multiple loops. The first displaying the latest story from a specific category, in this case "Suns" or catid 3.

    My code however seems to have some issues! I copied it straight from http://codex.wordpress.org/The_Loop but still it's not showing up. I get a blank page at http://www.azfans.com/blogs/suns

    <?php $my_query = new WP_Query('category_name=Suns&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>
      <?php endwhile; ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>
      <?php endwhile; endif; ?>

    Also, I want the remaining posts in the second loop to come from the same category, Suns, or catid 3. Can someone please help me with this code?

    Thank you!

    Jon

  2. ikiru
    Member
    Posted 6 years ago #

    I haven't looked at it very closely, but where did your endforeachs come from? I don't see why they'd be there.

  3. dbUNIT16
    Member
    Posted 6 years ago #

    Good catch, I must have pasted incorrectly!

    I have edited for it to read:

    <?php $my_query = new WP_Query('category_name=suns&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile; ?>
        <!-- Do other stuff... -->
      <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile; endif; ?>

    I have put this up at http://www.azfans.com/blogs/suns2/

    For some reason the rest of the posts beyond the first aren't showing up! Also, the title of the page (Suns2) is showing up below the first item!

  4. JohnPope
    Member
    Posted 6 years ago #

    I can't see any reason why that won't work, I would like to see more of the php file though, maybe you've got something else around somewhere that is screwing it up.

    What you do have is

    <li></li>

    not contained in a

    <ul></ul>

    - so that is one little thing to sort out.

  5. dbUNIT16
    Member
    Posted 6 years ago #

    Ahhh! This is so frustrating! Here is my entire page! Thank you all for the help! BTW, I'm running 2.5.1, is that makes any difference...

    <?php
    /*
    Template Name: Suns2
    */
    ?>
    <?php get_header(); ?>
    <body>
      <!-- header -->
      <div id="header">
      <div id="logo">
      <h1>
    	<a href="http://www.azfans.com" title="azFans.com - Smarter. Prouder. Louder."><span></span>azFans.com</a>
    	</h1>
    
    </div>
      </div>
      <!-- navigation bar -->
      <div id="navcontainer">
    
    	<ul id="navlist">
    		<li><a id="tabz"  class="active" href="/" title="The home for Arizona sports fans!">Home</a></li>
    		<li><a id="taba"  href="/blogs/" title="Read and write about your favorite Arizona sports teams and players!">Blogs</a></li>
    		<li><a id="tabb"  href="/forums/" title="Discuss hot topics in the world of desert sports!">Forums</a></li>
    		<li><a id="tabc"  href="/store/" title="Shop for Arizona sports fan apparel, jerseys, hats, and more!">Store</a></li>
    	</ul>
    	<ul id="teamlist">
    		<li><a id="tabd"  href="/suns/" title="The latest on Steve Nash, Amare Stoudemire, and the rest of the Phoenix Suns!">Suns</a></li>
    		<li><a id="tabe"  href="/d-backs/" title="The inside scoop on your NL West Champion Arizona Diamondbacks!">D-Backs</a></li>
    		<li><a id="tabf"  href="/cardinals/" title="News and notes on Matt Leinart and your Arizona Cardinals!">Cardinals</a></li>
    		<li><a id="tabg"  href="/coyotes/" title="Phoenix Coyotes news, blogs, and discussions!">Coyotes</a></li>
    		<li><a id="tabh"  href="/more/" title="More Arizona Sports Teams!">+ More</a>
    		    <ul>
                      <li><a href="" title="Arizona State University Sun Devils">Sun Devils</a></li>
                      <li><a href="" title="University of Arizona Wildcats">Wildcats</a></li>
    				  <li><a href="" title="Northern Arizona Univesity Lumberjacks">Lumberjacks</a></li>
                      <li><a href="" title="Phoenix Mercury basketball">Mercury</a></li>
                      <li><a href="" title="Arizona Rattlers arena football">Rattlers</a></li>
    				  <li><a href="" title="Arizona high school sports">High School</a></li>
               </ul>
    		   </li>
    	</ul>
    	<ul id="joinlist">
    		<li><a id="tabi"  href="/join/" title="Become an azFan today! Free!">Join Now!</a></li>
    	</ul>
    	</div>
    	<div id="topbarcontainer">
    	<ul id="secondtopnavlist">
    		<li><a id="tabb"  href="/blogs/" >Recent Posts</a></li>
    		<li><a id="tabc"  href="/forums/" >Top Posts</a></li>
    		<li><a id="tabd"  href="/forums/" >Top Blogs</a></li>
    		<li><a id="tabd"  href="/forums/" >Tags</a></li>
    		<li><a id="tabd"  href="/forums/" >Get a Blog</a></li>
    	</ul>
    	<div id="search">
    	<span class="date">Search:</span><input type="text" name="textfield" class="textarea">
    	</div>
    	</div>
      <div id="container">
    
    		<div id="main">
    			<h3><a href="http://www.azfans.com/thewire">Recent Blog Posts</a></h3>
    			<a href="#" class="rsslink">Subscribe</a>
    
      <?php $my_query = new WP_Query('category_name=suns&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile; ?>
        <!-- Do other stuff... -->
      <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile; endif; ?>
    
                <h3><?php _e('Latest Forum Posts'); ?></h3>
    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/rss.php');
    $rss = fetch_rss('http://azfans.com/forums/external.php?type=RSS2&forumids=2');
    $maxitems = 10;
    $items = array_slice($rss->items, 0, $maxitems);
    ?>
    
    <ul>
    <?php if (empty($items)) echo '<li>No items</li>';
    else
    foreach ( $items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a><?php echo $item['pubDate']; ?></li>
    <?php endforeach; ?>
    </ul>
    
    		</div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic