I am using the Siren Template. In homepage.php this code is used to display the portfolio content
print_excerpt(200);
But I to need show the content only before <!--more-->
I have used this:
the_content( $more_link_text, FALSE);
but it is not working. It shows all the content
I am using the Siren Template. In homepage.php this code is used to display the portfolio content
print_excerpt(200);
But I to need show the content only before <!--more-->
I have used this:
the_content( $more_link_text, FALSE);
but it is not working. It shows all the content
Share Improve this question edited Jun 10, 2014 at 4:22 Pieter Goosen 55.4k23 gold badges115 silver badges210 bronze badges asked Jun 10, 2014 at 1:57 MajidGhMajidGh 1031 gold badge1 silver badge5 bronze badges 2- This is a premium theme that we don't have access to – Pieter Goosen Commented Jun 10, 2014 at 4:25
- i use free version topwpthemes/siren – MajidGh Commented Jun 12, 2014 at 0:14
2 Answers
Reset to default 26You can use the WordPress function get_extended
to fetch the different parts of a string (the part before and the part after the <!--more-->
tag). get_extended
returns an array with three keys, of which the keys main
and extended
are important: $arr['main']
contains the part before the more tag, and $arr['extended']
the part after the more tag.
This would yield something like:
// Fetch post content
$content = get_post_field( 'post_content', get_the_ID() );
// Get content parts
$content_parts = get_extended( $content );
// Output part before <!--more--> tag
echo $content_parts['main'];
Unfortunally it seems like all functions in WordPress that are supposed to render the excerpt (get_extended
, get_extended
) don't apply HTML tags nor convert carriage returns in paragraphs as aspected.
If you need to render the excerpt with formatting, I suggest that you use this code:
global $more;
$more_backup = $more;
$more = 0;
the_content('');
$more = $more_backup;
With this work-around you are telling to the_content() function that it is inside a loop, getting the content before the more tag.