Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Gabriel Ward
Gabriel Ward
20,222 Points

Selecting half the content of a post.

I want to display the content of my posts in over two columns. Does anyone know how I might do this? I was thinking using multiple loops, with each column having its own div, and within each div there is a loop. I'm not sure how to call the first half the post in the first column and the second half the post in the second though. Thanks for any help!

1 Answer

Hi Gabriel,

Not sure if this is the type of thing that you were thinking but it could be possible using CSS (specifically CSS3).

The Multi-Column layout page on w3schools will go over the basics but CSS Tricks also has an article on making sure this is responsive.

You wouldn't need to use multiple loops this way.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Rich,

Thank you for your suggestion. I have't tried it yet but it looks like it'd work. So I'll give it a go. Just for interest sake though, is it possible to do what I was at first thinking, in terms of selecting half of the content of a post.

Just because at the moment I'm using Guil Hernandez's grid system that he teaches in his CSS course here on Treehouse, as my static template that I'm trying to convert into a Wordpress theme. And within that frame work I'm thinking that selecting certain parts of content in each column would be the first option to try. His grid system doesn't use the multi-column syntax as mentioned in your two links above. I am going to have a go at making that work though.

Cheers for your help

Gabe

Hi Gabe,

Honestly, I haven't tried it to be 100% sure. One way that could work would be to use the Advanced Custom Fields plugin. You'd then create the fields you wanted and put the different sections of text within separate fields so you could position them exactly where you need on the page.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Rich,

THanks for your recommendation regarding multi-columns. It worked no problem so I now have a solution.

I do have another thing I'm having problems with. The featured images of posts are not displaying correctly. Instead of cropping and remaining in proportion, they are stretching. Do you have any suggestion on what the problem might be? I'm trying to play around with the set_thumbnail_size in functions.php. So far no luck.

Really appreciate all your help.

Hi Gabe,

No problem, It's a little bit of a guess but it sounds as though it's CSS related. One way to check would be to use the browser developer tools (usually F12 when in the browser or right click on the image and select 'Inspect Element').

You'll then be able to see if the width and height is restricted in the style sheet.

Hope that helps :)

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Rich,

I just posted the following question in the forum

I want to have my thumbnails be responsive in size and also remain in proportion. However the images don't keep their proportion when the browser is changed in size.

Here's my relevant code, in particular the feat-img div.

home.php

<?php while ( have_posts() ) : the_post(); ?>
    <?php if( get_the_post_thumbnail() ) : ?>
                        <div class = 'image'>   
                            <div class="feat-img">
                                <?php the_post_thumbnail( array (300, 300) ); ?>
                            </div>
                            <div class ='text'><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div>
                        </div>    
                                <?php endif; ?> 
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
    </div>

style.css

.feat-img {
        max-width: 70%;
        margin: 0 auto;

}

I've been playing around with this for a while and not had any luck. I'm not sure if the feat-img CSS needs to be changed or whether something needs to be changed in home.php