[wp-trac] [WordPress Trac] #21894: <!--more--> tag does nothing in secondary loops when is_single because of $more global
WordPress Trac
wp-trac at lists.automattic.com
Fri Sep 14 20:11:48 UTC 2012
#21894: <!--more--> tag does nothing in secondary loops when is_single because of
$more global
--------------------------+-----------------------------
Reporter: jeremyclarke | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version: trunk
Severity: normal | Keywords:
--------------------------+-----------------------------
In the sidebar of single posts I have a listing of short posts from a
particular category. We recently started using the {{{<!--more-->}}}
system to define teasers because in this case excerpts are overkill. The
"more" system works for archive views but does nothing in the sidebar of
single posts. The reason is the overly global nature of the {{{global
$more}}} variable. It gets defined in {{{setup_postdata()}}} like this:
{{{
if ( is_single() || is_page() || is_feed() )
$more = 1;
}}}
Then in {{{get_the_content()}}} global $more is checked to determine
whether to apply the effect of the {{{<!--more-->}}} tag or not:
{{{
if ( $more ) {
// show full content with span ID
} else {
// show intro text and more link
}
}}}
This means that any time {{{is_single()}}} is true all posts shown during
the pageload ignore {{{<!--more-->}}}, even those who's {{{is_single}}}
view we are not on.
This seems like an understandable result of the unpopularity of the more
tag (and rareness of showing "full" posts in secondary loops), but also
something that should be fixed. Only the post who's single view we are
looking at should have the more tag disabled based on the
{{{is_single()}}} check.
'''SOLUTION'''
As far as I can tell what's needed is to modify {{{get_the_content()}}}
and in addition to using {{{global $more}}}, also check if the post being
shown is the same as {{{get_queried_object()}}}. My first instinct was to
just add the check in the {{{if}}} statement above:
{{{
if ( $more AND ( $post-ID == get_the_queried_object_id() ) ) {
// show full content with span ID
} else {
// show intro text and more link
}
}}}
Unfortunately that will screw with the {{{is_feed()}}}-related checks for
{{{global $more}}}. Overall my investigation of {{{$more}}} is making me
think it should be removed entirely, as it's only used a few times and in
all cases its meaning is vague.
Either way I think the simplest way to handle the issue in
{{{get_the_content()}}} without completely stripping out {{{$more}}} is to
use {{{$more}}} as the base for a {{{$show_full_content}}} variable, then
set that to false if {{{$post->ID}}} doesn't match
{{{get_queried_object_id()}}}:
{{{
$show_full_content = $more;
if ( is_single() OR is_page() ) {
if ($post->ID != get_queried_object_id())
$show_full_content = false;
}
}}}
The new variable gives a better sense of what it will do inside this
function, and lets us change the value without stomping the {{{global
$more}}}. The attached patch fixes {{{get_the_content()}}} as described
above.
If core devs are willing to I think the best solution would be to remove
all uses of {{{$more}}} and simply replace them with the appropriate logic
for the given situation like I've done above for {{{get_the_content()}}}.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21894>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list