I am using the following code:
<?php the_excerpt(); ?>
This trims after 50 ish words, way after the <!--more-->
I added in the post's source.
This, instead, correctly trims out the part before <!--more-->
as expected.
<?php the_content("", TRUE); ?>
How do I change the_excerpt()
so that it returns the part before <!--more-->
?
I tried using get_extended()
but it does not produce the same output as the_excerpt()
; specifically, it does not add <p>
tags, and probably something else.
Thank you in advance.
I am using the following code:
<?php the_excerpt(); ?>
This trims after 50 ish words, way after the <!--more-->
I added in the post's source.
This, instead, correctly trims out the part before <!--more-->
as expected.
<?php the_content("", TRUE); ?>
How do I change the_excerpt()
so that it returns the part before <!--more-->
?
I tried using get_extended()
but it does not produce the same output as the_excerpt()
; specifically, it does not add <p>
tags, and probably something else.
Thank you in advance.
Share Improve this question asked Jun 17, 2019 at 7:52 WesAtWorkWesAtWork 111 Answer
Reset to default 0the_excerpt()
does not recognise or support the <!-- more -->
tag. From the documentation:
The
<!--more-->
quicktag requires templates to usethe_content()
whereas using excerpts requires, and allows, template writers to explicitly choose whether to display full posts (usingthe_content()
) or excerpts (usingthe_excerpt()
).
The point is that the_excerpt()
allows theme authors (you) to require an excerpt. This is automatically created by trimming the content, but if the user needs a specific excerpt then they can enter a manual excerpt. Either way they cannot accidentally display the full post content.
On the other hand the_content()
lets the user decide whether or not to use an excerpt. If they do want one, then they use the <!-- more -->
tag. If they don't, then they leave it out and the full post will be displayed.
As a theme author you need to decide which you should support. If displaying the full content of the post would break your layout, then you should use the_excerpt()
, but if the theme would look fine either way, then use the_content()
.
If you want the user to decide between these options then you could create a Customiser setting that let's the user choose. Then in your templates you could check this value and use the appropriate tag:
<?php
if ( 'excerpt' === get_theme_mod( 'setting_name_here' ) ) {
the_excerpt();
} else {
the_content( '', true );
}
?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395396a4625853.html
评论列表(0条)