SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change appearance of "sticky" post in WordPress

    Ok, Ive developed a theme where basically the posts display the title, the date and category (which is highlighted), the post contents and a read more link... However i have now decided to add an introductory "sticky" post, just an "about me" post which will stay at the top... I know how to make the posts sticky ok, what im wondering though is how i customize this posts appearance compared to all the standard non-sticky posts?

    I looked at the html and the sticky post doesn't seem to have a class or anything that defines it as a sticky post, so can't just add the class name to the css and give it different rules.. I would like this post to only display the title, no date or category or read more link (as the entire post will be displayed), and possibly add a different background colour to this one..

    Anyone able to help?

    Much appreciated

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,775
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    You can test to see if the post is sticky then load a custom template.

    http://codex.wordpress.org/Function_Reference/is_sticky
    http://codex.wordpress.org/The_Loop

    If you don't get a more definitive answer within 24 hours, I'll see what I can do.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could target the post in CSS by its ID.
    If you use Firebug you will see the ID of each post, e.g

    article id="post-274"

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, although im going to need to use the php option as well i think if i only want "content" with this post and not title and no date/category/read more etc...

    am i right in thinking the loop should look like this for what i want?

    <section id="posts">

    <?php if (have_posts ()) : ?>
    <?php while(have_posts()) : the_post(); ?>

    <?php if(is_sticky()):?>
    <article id="sticky_post"><?php the_content(); ?></article>
    <?php endif;?>


    <article>
    <h2 class="post_title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

    <p class="date"><?php the_time('F jS, Y') ?><br />
    Posted in: <?php the_category(', ') ?></p>

    <div class="grey"><?php the_content(''); ?></div>

    <a href="<?php the_permalink() ?>" class="readmore">Read More...</a>
    </article>

    <?php endwhile; ?>

    <ul id="older_newer">

    <li id="older"><?php next_posts_link('Older Posts') ?></li>
    <li id="newer"><?php previous_posts_link('Newer Posts') ?></li>

    </ul>

    <?php else : ?>

    <h2>Nothing Here!</h2>

    <?php endif; ?>

    </section>

    I know that definitely doesnt seem right... jsut want to get some knowledge before i go messing with my theme again... the bold section is the bit with the is_sticky query.. what i want is for any "sticky" posts to only display content and with an id which i can target in my css, where the rest of the posts display as shown/formatted (with title, date, category and the read more link)

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe instead of <?php endif; ?> underneath the sticky post query it should be <?php elseif(!is_sticky()): ?> (ALL THE FORMATTING FOR NON STICKY POSTS) followed by <?php endif; ?>

    anyone? help greatly appreciated

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES! got it working with that second option there starting to really love wordpress development


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •