/ Published in: PHP
Create excerpts from text block from your wordpress content and add links page / post from the guid.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * usage: * $txt = new($post->post_content, 50, 'Read in full', '<span class="readmore">', '</span>', '<a><span>'); * echo $text->createExcerpt(); * */ class text{ public $text; public $length; public $allowedTags; public $readMoreText; //create internal variables from those passed to the class function __construct($text = '', $length = 50, $readMoreText = 'Read In Full...', $before = '', $after = '', $allowedTags = '<a>') { $this->text = $text; $this->length = $length; $this->readMoreText = $readMoreText; $this->before = $before; $this->after = $after; $this->allowedTags = $allowedTags; } //shorten text to required length public function shortenText() { //explode the string into an array of the length we want { //remove the excess string from the end of the array //create a string from the array //cleaning up //return return $textString . '... '; } else { return $this->text; } } //remove tags and other. public function cleanText($text){ //strip the text of html tags, except those we want //remove [] and their content //return return $strippedText; } //create output public function createExcerpt(){ global $post; //create output $output = ''; $output .= $this->cleanText($this->shortenText()); if($this->readMoreText !== '') { $output .= $this->before; $output .= ' <a href="'. $post->guid .'" title="'. $this->readMoreText . ': '. $post->post_title .'">'. $this->readMoreText . '</a>'; $output .= $this->after; } return $output; } }//end class//