• Resolved khantony

    (@khantony)


    Hello,
    I have made a static page for my home page and I also have a blog page for my latest blog posts. Now my home page is working fine showing the latest post using query_post() method. But I want to show latest 3 posts in 3 columns. How can I do that?. I used <?php query_posts(‘showposts=1’); for showing the latest post but if use ‘showposts=3’ then 3 posts are showing one by one. but I want to show them side by side in 3 columns.

Viewing 2 replies - 1 through 2 (of 2 total)
  • its all css my friend!

    I’ll try to describe, I’m a terrible teacher!

    Basically, you have your loop, its got your divs laid out. You query 3 posts. To have them side by side in 3 colums, you just lay it out that way in css.

    Soooo, normally your loop is started, then the div is layed out like <div id="post-<?php the_ID(); ?>"> or something. You can add in a class to that. like class=”col” or something.

    You could then define that class in css to be a certain size. Basically do the math, and make sure it’s less than 1/3 of the width of the parent element. So if you assign a width less than 1/3 the parent element, 3 columns will fit side by side.

    Finally, after defining the element, and defining it as 1/3 the width… you float it left with float:left

    if you query 3 posts, have them set to a width less than 1/3 of the parent container and float them all left, the first floats left, the second floats left, but stops to the right of the first, and the third floats left, but stops to the right of the second. So they all line up!

    Just remember, the total width of the 3 columns, plus if you give any margins, must be less than the total width of the parent element. You can set the width in px, or %, so 300px x 3 would fit inside a parent container larger than 900px, or something like 30% would work too. You just have to remember any margins or padding assigned to the elements, or the parent container

    Thread Starter khantony

    (@khantony)

    That’s incredibly good solution my friend!

    Thanks a lot………

    Yes I find that it’s really easy to do with css. I was looking for some wordpress function to do the job(what a fool I am!!). Sometimes it happens. When you deal with some hard work you forget the simple solution.

    Anyway thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Showing latest 2/3 posts on a static home page’ is closed to new replies.