/data/wpcom-themes/blix/BX_functions.php

https://gitlab.com/Blueprint-Marketing/wordpress-unit-tests · PHP · 103 lines · 52 code · 15 blank · 36 comment · 13 complexity · 4339ec83562c112c91a3528ae1245769 MD5 · raw file

  1. <?php
  2. /**
  3. * Function BX_get_recent_posts
  4. * ------------------------------------------------------
  5. * Outputs an unorderd list of the most recent posts.
  6. *
  7. * $current_id this post will be excluded
  8. * $limit max. number of posts
  9. */
  10. function BX_get_recent_posts($current_id, $limit)
  11. {
  12. global $wpdb;
  13. $posts = $wpdb->get_results("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_status='publish' AND post_type='post' ORDER BY post_date DESC LIMIT " . $limit);
  14. foreach ($posts as $post) {
  15. $post_title = stripslashes($post->post_title);
  16. $permalink = get_permalink($post->ID);
  17. if ($post->ID != $current_id) echo "<li><a href=\"" . $permalink . "\">" . $post_title . "</a></li>\n";
  18. }
  19. }
  20. /**
  21. * Function BX_get_pages
  22. * ------------------------------------------------------
  23. * Returns the following of all WP pages:
  24. * ID, title, name, (content)
  25. *
  26. * $withcontent specifies if the page's content will
  27. * also be returned
  28. */
  29. function BX_get_pages($with_content = '')
  30. {
  31. global $wpdb;
  32. $query = "SELECT ID, post_title, post_name FROM " . $wpdb->posts . " WHERE post_status='publish' AND post_type='page' AND post_parent = '0' ORDER BY menu_order ASC";
  33. if ($with_content == "with_content") {
  34. $query = "SELECT ID, post_title,post_name, post_content FROM " . $wpdb->posts . " WHERE post_status='publish' AND post_type='page' ORDER BY menu_order ASC";
  35. }
  36. return $wpdb->get_results($query);
  37. }
  38. /**
  39. * Function BX_excluded_pages()
  40. * ------------------------------------------------------
  41. * Returns the Blix default pages that are excluded
  42. * from the navigation in the sidebar
  43. *
  44. */
  45. function BX_excluded_pages()
  46. {
  47. $pages = BX_get_pages();
  48. $exclude = "";
  49. if ($pages) {
  50. foreach ($pages as $page) {
  51. $page_id = $page->ID;
  52. $page_name = $page->post_name;
  53. if ($page_name == "archives" || $page_name == "about" || $page_name == "about_short" || $page_name == "contact") {
  54. $exclude .= ", ".$page_id;
  55. }
  56. }
  57. $exclude = preg_replace("/^, (.*?)/","\\1",$exclude);
  58. }
  59. return $exclude;
  60. }
  61. /**
  62. * Function BX_shift_down_headlines
  63. * ------------------------------------------------------
  64. * Shifts down the headings by one level (<h5> --> </h6>)
  65. * Used for posts in the archive
  66. */
  67. function BX_shift_down_headlines($text)
  68. {
  69. $text = apply_filters('the_content', $text);
  70. $text = preg_replace("/h5>/","h6>",$text);
  71. $text = preg_replace("/h4>/","h5>",$text);
  72. $text = preg_replace("/h3>/","h4>",$text);
  73. echo $text;
  74. }
  75. /**
  76. * Function BX_remove_p
  77. * ------------------------------------------------------
  78. * Removes the opening <p> and closing </p> from $text
  79. * Used for the short about text on the front page
  80. */
  81. function BX_remove_p($text)
  82. {
  83. $text = apply_filters('the_content', $text);
  84. $text = preg_replace("/^[\t|\n]?<p>(.*)/","\\1",$text); // opening <p>
  85. $text = preg_replace("/(.*)<\/p>[\t|\n]$/","\\1",$text); // closing </p>
  86. return $text;
  87. }
  88. ?>