WordPress.org

Ready to get started?Download WordPress

Forums

Posts with different line spacings? (4 posts)

  1. billynino
    Member
    Posted 3 years ago #

    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

  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    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.

  3. billynino
    Member
    Posted 3 years ago #

    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

  4. MicheleMoore-Happy1
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic