Is there a known way to show the very first sentence of the content of a blog post? I know I can use the_excerpt();
but client has a strange requirement to show only the first sentence. If there is a known method for this that would be great to know. I appreciate it.
-
Did you try this? wordpress.stackexchange.com/questions/108826/…– Howard EMay 3, 2016 at 14:40
-
i read that and tried it. for one it doesn't work for me; for two i want this to be first sentence of the content and not excerpt. if i am forcing user to type in an excerpt that they would just type in the first sentence and i wouldn't need all of this.– Zach SmithMay 3, 2016 at 14:52
-
What exact part do you have issue with? Retrieving content? Cutting down to a first sentence?– RarstMay 3, 2016 at 15:17
1 Answer
Assuming you want to cut off a string after the first full stop you could use something like this:
$the-content = "This is the first sentence. And this is the second";
$cut-in-two = explode('.', $the-content, 2);
$first-sentence = $cut-in-two[0];
-
-
@HollerTrain. Do you mean you're manipulating the result of
the_content()
with javascript on the user end? Then it won't work, obviously. However, if you're building a page on the server end with php,get_the_content()
gives a string that can be manipulated as shown. You'd have to replace the first line with$the-content = get_the_content();
– cjbjMay 4, 2016 at 8:35