I have a situation where users don't want to format quotes in post body and want to just paste their content, assign a quote in a custom field, and the template will now render the quote when viewing their post on the website.
The way I decided to do it was to add a custom field on the post and call it in the template. I want to see if there's a method of splitting the_content()
, printing the custom field, and then printing the remaining the_content()
.
So far I have:
<?php
$quoteCheck = array();
$key = 'quote';
$quote = get_post_meta($post->ID, $key, $single = true);
if(!empty($quote)){
$quoteCheck[] = array(
'quote' => $quote
);
}
if(!empty($quoteCheck)){
//print 1st half the_content();
?>
<blockquote><?php echo $quote['quote']; ?></blockquote>
<?php
//print 2nd half the_content();
} else {
the_content();
}
?>
This checks if a quote has been added as a custom field and if true it formats the content or else just prints the content.
Ideally I'd like to consider two things:
1) Determining the size (probably character count) of the content and splitting it in the center
2) Determining the next paragraph after the split to perform the actual split.
Ie I wouldn't want to split mid-word or mid-sentence. I'd like to find the middle, then find the next paragraph break and perform the split there.
I've been reviewing Google for splitting the content but haven't come up with anything meaningful that requires user formatting when creating the post. I've found reference to adding a <!-- more -->
break in the page but if they can't add <blockquote>
to the page then they can't add <!-- more -->
to the page either.