• Hi

    I was wondering if you can have different line spacings for different posts with wordpress and if so then how do you do this? I want to make the spacing for poetry posts closer but leave prose posts as they are.

    cheers

    Bill

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yes you can, but it’s going to take a little custom work on the theme.

    The first thing you’ll want to do is to modify the loop to add a specific CSS class to your different types of posts.

    One way to do this would be to add the posts’ category slugs to their wrappers. For instance, if the loop looks something like:

    <?php
    if(have_posts()) : while(have_posts()) : the_post();
    ?>
    <div class="post">
      <h2><?php the_title(); ?></h2>
      <?php the_content(); ?>
    </div>
    <?php
    endwhile; endif;
    ?>

    You could change it to looks something like:

    <?php
    if(have_posts()) : while(have_posts()) : the_post();
    ?>
    <div class="post <?php echo wp_get_object_terms($post->ID, 'category'); ?>">
      <h2><?php the_title(); ?></h2>
      <?php the_content(); ?>
    </div>
    <?php
    endwhile; endif;
    ?>

    Note: I haven’t used the wp_get_object_terms() function before, so I’m not 100% certain if the code above will work as expected.

    The next thing you’ll need to do is edit the style.css file to assign a slightly different style to the posts based on the class you added. For instance, if the classes that were added were “prose” and “poetry”, you could simply add something like:

    .poetry {
    line-height: 1.1em;
    }
    .prose {
    line-height: 1.5em;
    }

    or however you would like the style changed.

    Good luck.

    Thread Starter billynino

    (@billynino)

    Hi Curtiss,
    this looks promising but unfortunately being a novice with CSS I don’t know where to locate the loop. I know how to edit the style.css file but can you tell me where to find the loop

    cheers

    Bill

    Question: Is it possible to add something to the code for each paragraph to affect line spacing like you can change font and font size?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Posts with different line spacings?’ is closed to new replies.