How to Tweak the Title Font-size for an Individual Post?

Discussion in 'WordPress' started by loveofwords, Jun 23, 2010.

  1. #1
    I know that we can tweak the font-size of post titles using style.css file in wordpress, but doing that affects all posts. My question is how to do it to an individual post, without affecting the other posts' settings.

    To be precise, I'd like to know how I can show my latest post's title bigger while retaining others as they are.
    As I'm showing only my latest post in full, I want its title to be bigger and prominent than the rest.

    Can somebody tell me the hack to show only my first (latest) post with a larger title?
     
    loveofwords, Jun 23, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use a conditional statement to add a class to the heading of the first post:
    
    <?php if ( !is_paged() && ($post == $posts[0]) ) ?>
       <h2 class="firstpost"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php else : ?>
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php endif; ?>
    
    Code (markup):
    Add this to the stylesheet:
    
    .firstpost { font-size: 20px; }
    
    Code (markup):
    It only applies the style on the first page, not on pages after that. If you want it on every page, remove the !is_paged() && bit.
    Hope that works, I haven't tested it. :)
     
    Cash Nebula, Jun 23, 2010 IP
  3. hmansfield

    hmansfield Guest

    Messages:
    7,904
    Likes Received:
    298
    Best Answers:
    0
    Trophy Points:
    280
    #3
    You can also use <b><em><i> ( and the corresponding closing tags) right in the title to tweak the on page appearance.
     
    hmansfield, Jun 23, 2010 IP
  4. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Unfortunately, Wordpress is not that simple. It has a PHP loop that adds the markup for each post.
    Applying a style to it affects all the posts, unless there is also code to select certain posts.
     
    Cash Nebula, Jun 23, 2010 IP
  5. loveofwords

    loveofwords Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the response. What should I substitute the above code for? I used it in place of this:

    <?php if ($postcount == 1 && !is_paged()) : ?>
    <?php the_content(__('Read more'));?><div style="clear:both;"></div>
    <?php else : ?>
    <?php the_excerpt(); ?>
    <?php endif; ?>

    And the site went blank. I haven't learned CSS/PHP - so I can implement what you say only if you explain how to do it exactly. :)

    Here's the my home page's code (Index.php) if you like to have a look: http://pastebin.com/HNGaXcJJ
     
    loveofwords, Jun 27, 2010 IP
  6. teamnirvana

    teamnirvana Active Member

    Messages:
    844
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    60
    #6
    You need to insert the given code after this line:

    Try it and let us know.
     
    teamnirvana, Jun 27, 2010 IP
  7. loveofwords

    loveofwords Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Nope, that didn't fix it either. :(

    I raised the same issue on WordPress forums and the moderator suggested a different hack which looked like it would fix it, but it altered the body of the post instead of the title. See if you can figure out something around it to make things work, here.

     
    loveofwords, Jul 7, 2010 IP