• Resolved billymo

    (@billymo)


    I’m creating a site that lists of blog posts in 6 categories. I have the loop set up the way I want with one exception. I want to wrap each category in a <div>. If I have each query create a <div>, it creates <div>s for every post title. Any suggestions? Where can I insert those <div> tags?

    function giftlist_indexloop() {
    		query_posts("posts_per_page=10");
    					if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<?php echo "<h3><a href='"; the_permalink(); echo "'>"; the_title(); echo "</a></h3>"; ?>
    					<?php endwhile; else: ?>
    					<h2>Eek</h2>
    					<p>There are no posts to show!</p>
    					<?php endif ;
    
    					wp_reset_query();
    
    		query_posts("posts_per_page=10&cat=3");
    					if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<?php echo "<h3><a href='"; the_permalink(); echo "'>"; the_title(); echo "</a></h3>"; ?>
    					<?php endwhile; else: ?>
    					<h2>Eek</h2>
    					<p>There are no posts to show!</p>
    					<?php endif;
    					wp_reset_query();
    
    		query_posts("posts_per_page=10&cat=4");
    					if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<?php echo "<h3><a href='"; the_permalink(); echo "'>"; the_title(); echo "</a></h3>"; ?>
    					<?php endwhile; else: ?>
    					<h2>Eek</h2>
    					<p>There are no posts to show!</p>
    					<?php endif;
    					wp_reset_query();
    
    ...

Viewing 3 replies - 1 through 3 (of 3 total)
  • wrap each section completely…..

    the div would start before the query posts and end after the endif

    guess in your code they’d hafta be echoed out…..

    Thread Starter billymo

    (@billymo)

    TWO DAYS! Two days of searching and all it required was “echo”. I guess I need to go ahead and buy that PHP book if I can’t figure out something that simple. Thanks so much Rev. It worked perfectly.

    if you are inside of php code already, you have to echo out your html stuff.

    function giftlist_indexloop() {
    		query_posts("posts_per_page=10");
    					if (have_posts()) : while (have_posts()) : the_post(); ?>

    this is all a block of php code, as there is no opening <?php shown it must’ve opened earlier….but at the end there is a ?>

    Glad you got it!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Wrap a query in a div’ is closed to new replies.