• Hello,

    I’m making homepage of my wordpress blog which is a table with four columns and four rows. Each cell is a image with link to a post. Is it possible to have different style for first or last post item on each row?
    P.S. it is not created with tables, but I just wanted to describe how it is look like.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yes.

    You can style each div separately. Actually you’ll have to style each div separately to create that type of grid layout, by floating four divs for each row.

    Thread Starter torozov

    (@torozov)

    I’m using this to show the posts on the homepage:

    <?php query_posts($query_string.'&posts_per_page=16'); ?>
    		<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div class="POST">
    
                	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    				<img src="https://site.com/<?php the_title(); ?>.png" width="200px" height="150px" alt="<?php the_title(); ?> image" />
    				</a>
    				</div>
                    <?php endwhile; ?>
    
    				<?php else : ?>
    
            <h2 class='center'>No posts found</h2>
    
            <?php endif; ?>

    The problem is that each post is with class POST and I need some way to put different class on first or last post on each row.

    I’m not sure if you can do this with php, but you might try an if statement.

    Since the elements of the the array the_post() start with 0 and go to whatever number of elements there are.

    For the first post…

    if the_post() == the_post(0)
    <div class=”firstpost”>

    I’m not sure of the syntax here, so I’m substituting num_posts for whatever the actual function is that returns the number of posts.

    For the last post…

    if the_post() == num_posts – 1
    <div class=”lastpost”>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post style’ is closed to new replies.