WordPress.org

Ready to get started?Download WordPress

Forums

Style latest post as sticky (3 posts)

  1. bg347
    Member
    Posted 2 years ago #

    Hi,

    I want to style the latest post in the same way that my theme styles sticky posts on my homepage.

    Essentially what I am trying to do is style the latest blog post in a particular way.

    And when I say latest post, I mean the latest of all categories, bar one particular one.

    Ideas?

    Thanks!

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    guessing that the styling is triggered by the post_class() .sticky, try to use a filter;

    add this to functions.php of your theme:

    add_filter('post_class','add_sticky_class_to_latest_post');
    function add_sticky_class_to_latest_post($classes) {
    if($wp_query->current_post==0 && !is_paged() && is_home() && get_post_type() == 'post' ) $classes[] = 'sticky';
    return $classes;
    }
  3. bg347
    Member
    Posted 2 years ago #

    Thanks! How do I exclude a particular category from being included?

    And, how do I also include images in the 'sticky' formatting? I'm using the origin theme as below

    <?php do_atomic( 'before_entry' ); // origin_before_entry ?>
    						<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
    							<?php do_atomic( 'open_entry' ); // origin_open_entry ?>
    							<?php if ( current_theme_supports( 'get-the-image' ) ) {
    								if ( is_sticky ( $post->ID ) ) {
    								get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'image_class' => 'featured' ) );
    								} else {
    								get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'thumbnail', 'image_class' => 'featured' ) );
    								}
    							} ?>

    You'll see that it checks if a post is sticky and then calls the image correctly. How can I apply this image settings when the post is sticky to the latest post?

    Thanks - much appreciated!

Topic Closed

This topic has been closed to new replies.

About this Topic