• tvance929

    (@tvance929)


    So I’m trying to build a list based on the last 12 posts.

    I thought I could include something like this in Single.php page:

    <?php                             query_posts('category_name=volunteerspotlights&showposts=12&orderby=date&order=DESC');
                                echo '<ul style="list-style: none;">';
    
                                while (have_posts()) : the_post();
                                echo '<li style="width: 50%; float: left;"><a href="'. get_permalink() . '"><div style="font-size: 14px; font-weight: bold;">' . get_the_title() . '</div><div class="archiveName">' . get_the_date('F') . '</div></a></li>';
                                endwhile;
    
                            echo '</ul>';
                           ?>

    But as soon as I put that query_posts line in, the posts will no longer load, the browser just loads forever as if I am in an infinite loop or something. Anyone have any suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • sarahfrantz

    (@sarahfrantz)

    I would try a different method, I use:

    <?php $recent = new WP_Query(); ?>
    			<?php $recent->query('category_name=whateverhere&showposts=12&orderby=date&order=DESC'); ?>
    			<?php while($recent->have_posts()) : $recent->the_post(); ?>

    then I call the details I want.. I also put the

      tag before the entire query itself, only using the
    • tag after I ask for the posts.. and I close the
    • before the endwhile. (Placing the
      outside of the entire thing totally.
    sarahfrantz

    (@sarahfrantz)

    ugh, I forgot to put code tags on it,

    I mean I put the <ul> tag before the entire query itself, only using the <li> tag after I ask for the posts.. and I close the <li>' before the endwhile. (Placing the

      ` outside of the entire thing totally.

    Thread Starter tvance929

    (@tvance929)

    Thanks! But something is still going wrong for me… I did this:

    <ul>
    			<?php $recent = new WP_Query(); ?>
    			<?php $recent->query('category_name=volunteerspotlights&showposts=12&orderby=date&order=DESC'); ?>
    			<?php while($recent->have_posts()) : $recent->the_post(); ?>
    			    <li style="width: 50%; float: left;">
    				<a href='<?php get_permalink(); ?>'>
    			    		<div style="font-size: 14px; font-weight: bold;"><?php get_the_date('F'); ?></div>
    						<div class="archiveName"><?php get_the_title(); ?></div>
    				</a>
    			   </li>
    			<?php endwhile; ?>
    			    </ul>

    I KNOW that its getting the posts because I only have 2 of those category and when I look at the HTML source, I have 2 LI items… but there is nothing in permalink or title or date.. ??

    *** WOOT .. nvrmind. Got it.. with that WP_Query its just the_title, the_date and the_permalink. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Trying to query posts in single.php and the posts never load – infinite loop?’ is closed to new replies.