Grabs the textual content of a Post and style it


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * Grabs the text content from a Page that is meant to be a blurb
  3.  * on another Page.
  4.  * 1. Create a Page and insert text to be used as the blurb.
  5.  * 2. Give the post slug a name.
  6.  * 3. Call get_blurb() from where the blurb should be inserted.
  7.  *
  8.  * @param pagename - post slug of the Page
  9.  * @param keeptags - tag list to allow in the text
  10.  * @return String - the blurb
  11.  */
  12. function get_blurb ($pagename, $keeptags='')
  13. {
  14. $q = new WP_Query('pagename='.$pagename);
  15. $content = '';
  16.  
  17. if ($content = $q->queried_object->post_content)
  18. {
  19. $content = strip_tags($content, $keeptags);
  20. }
  21. else {
  22. $content = 'This blurb does not exist. ';
  23. }
  24. return $content;
  25. }
  26.  
  27. function beautify_blurb ($content, $isIndex=FALSE)
  28. {
  29. if ($isIndex) {
  30. return preg_replace('/^<strong>/i', '<strong class="intro">',$content);
  31. }
  32. else {
  33. return preg_replace('/^<p><strong>/i', '<p class="intro"><strong>',$content);
  34. }
  35. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.