Archived topic
Custom CSS for sticky posts
4 replies · Started by Tom on October 7, 2015
Hi,
Is it possible to style a sticky post differently to the global settings for other posts? I'd like to use a different excerpt length, different image size/alignment and different text colour. I've used Simple Custom CSS to change the background colour and borders but the other settings don't seem to override the global settings. Any suggestions?
Hi Tom,
Tough questions.
Do you have the Blog add-on activated?
How about the Page Header add-on?
Let me know - I should be able to give you a couple functions :)
This CSS will change the post text color:
/* sticky post text color */
.sticky {
color: #f00; /* red */
}
Adding CSS: https://generatepress.com/knowledgebase/adding-css/
This function will change the sticky post excerpt length:
add_filter( 'excerpt_length', 'my_sticky_excerpt_length', 999);
function my_sticky_excerpt_length( $length ) {
if ( is_sticky() ) {
$length = 25;
}
return $length;
}
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
Hi Tom - yes, I have both activated.
bdbrown - thanks for the suggestions but neither of those work. I think they're perhaps being overridden by other elements of the theme?
Thanks both for your help.
Give this a shot for the excerpt length:
add_filter( 'excerpt_length', 'generate_custom_excerpt_length', 1000 );
function generate_custom_excerpt_length( $length ) {
if ( function_exists( 'generate_blog_get_defaults' ) ) :
$generate_settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);
$length = $generate_settings['excerpt_length'];
else :
$length = 55;
endif;
if ( is_sticky() ) {
$length = 25;
}
return $length;
}
Change the image size:
.sticky .post-image img {
max-width: 200px;
}
Alignment:
.sticky .post-image {
float: left;
}
Color:
.sticky .inside-article {
color: #222222;
}
