• Resolved sixfootjames

    (@sixfootjames)


    Hi!

    I am trying to wrap the_content(); in a div so that I can style it using css so that each post is next to each other, ending up in a two column layout situation.

    This is what I have tried in my code:

    <div class="entry-content">
            <h1><?php  the_title(); ?> </h1>
            <?php query_posts('cat=5&posts_per_page=4');
                if (have_posts()) : while (have_posts()) : the_post();?>
                <h2><?php the_title();?></h2>
                <?php
                    global $more;
                    $more = 0;
                    <div class="two-col">the_content();</div>
                    endwhile; endif;
                    // Reset Query
                    wp_reset_query();
    
            ?>
    
    </div>
    <div class="entry-content">
                        		<h1><?php  the_title(); ?> </h1>
    							<?php query_posts('cat=5&posts_per_page=4');
                                    if (have_posts()) : while (have_posts()) : the_post();?>
                                    <h2><?php the_title();?></h2>
                                    <?php
                                        global $more;
                                        $more = 0;
                                        '<div class="two-col">' . the_content(); . '</div>'
                                        endwhile; endif;
                                        // Reset Query
                                        wp_reset_query();
    
                                ?>
    
                        </div>

    Dreamweaver immediately pics up that there is an issue with the formatting of the syntax so clearly this is where I am going wrong. If someone would be so kind as to show me what I am doing wrong, I would appreciate!

    Many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • it was missing an echo statement & closing semi colon:

    <div class="entry-content">
            <h1><?php  the_title(); ?> </h1>
            <?php query_posts('cat=5&posts_per_page=4');
                if (have_posts()) : while (have_posts()) : the_post();?>
                <h2><?php the_title();?></h2>
                <?php
                    global $more;
                    $more = 0;
                    echo '<div class="two-col">the_content();</div>';
                    endwhile; endif;
                    // Reset Query
                    wp_reset_query();
    
            ?>
    
    </div>

    Or Option 2

    <div class="entry-content">
        <h1><?php  the_title(); ?> </h1>
    	<?php query_posts('cat=5&posts_per_page=4');
                  if (have_posts()) : while (have_posts()) : the_post();?>
                      <h2><?php the_title();?></h2>
                      <?php
                       global $more;
                       $more = 0;
                       echo '<div class="two-col">';
    		   the_content();
                       echo '</div>';
                       endwhile; endif;
                       // Reset Query
                       wp_reset_query();
              ?>
     </div>

    make sure to close php ttags before html, and opening new php when the code goes back to php;
    http://www.w3schools.com/php/php_syntax.asp

    either:

    $more = 0; ?>
                    <div class="two-col"><?php the_content(); ?></div>
                    <?php endwhile; endif;

    or:

    $more = 0;
                                    echo '<div class="two-col">';  the_content(); echo '</div>';
                                        endwhile; endif;

    or:

    $more = 0;
                                    echo '<div class="two-col">' . get_the_content() . '</div>';
                                        endwhile; endif;

    http://codex.wordpress.org/Function_Reference/get_the_content vs. http://codex.wordpress.org/Function_Reference/the_content

    Thread Starter sixfootjames

    (@sixfootjames)

    Thanks everyone, I will try these options now and come back with any problems I might have 🙂

    Thread Starter sixfootjames

    (@sixfootjames)

    This is what worked in the end…I had to change it slightly to wrap the <h2> tag as well…

    <div class="entry-content">
            <h1><?php  the_title(); ?> </h1>
            <?php query_posts('cat=5&posts_per_page=4');
                if (have_posts()) : while (have_posts()) : the_post();?>
                <?php echo '<div class="two-col">' ?>
                <h2><?php the_title();?></h2>
                <?php
                    global $more;
                    $more = 0;
    
                    the_content();
                    echo '</div>';
                    endwhile; endif;
                    // Reset Query
                    wp_reset_query();
                ?>
    
    </div>

    Thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to wrap the_content() in a div with a class’ is closed to new replies.