Opened 7 years ago
Last modified 6 years ago
#43294 new enhancement
Sticky class should be added regardless of where posts are queried
Reported by: | Selrond | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
post_class() function is only adding .sticky
class when is_home()
is true, basically
...if the query is for the blog homepage.
Check out the code in get_post_class() function
512 // sticky for Sticky Posts
513 if ( is_sticky( $post->ID ) ) {
514 if ( is_home() && ! is_paged() ) {
515 $classes[] = 'sticky';
516 } elseif ( is_admin() ) {
517 $classes[] = 'status-sticky';
518 }
519 }
This behavior complicates recognizing sticky post when using custom queries, as they're mostly used outside of homepage, which fails is_home()
check, requiring extra work to add .sticky
class where it should be.
I suggest removing the is_home()
check from the condition in get_post_class()
function.
Change History (3)
#2
in reply to:
↑ 1
@
7 years ago
@birgire my issue is really that .sticky
should be added to sticky posts regardless of how they are queried (default query or custom query).
Current implementation only adds .sticky
class to sticky posts when queried from default query (due to the is_home()
check.
I propose removing is_home()
check in post-template.php
which would enable adding .sticky
class to posts queried from custom queries.
@Selrond Welcome to WordPress core trac.
The
get_post_class()
function was introduced in 2.7 and there the sticky part was already with ais_home()
check:The sticky posts are injected within the
WP_Query::get_posts()
src:where the
$this->is_home && $page <= 1
restrictions looks very similar to the:check in
get_post_class()
in 4.9.So the
is_home()
check looks normal here or maybe I'm misunderstanding your proposal @Selrond ?