5 * ------------------------------------------------------
6 * This function is based on WP's built-in get_archives()
7 * It outputs the following:
9 * <h3><a href="link">Month Year</a></h3>
10 * <ul class="postspermonth">
11 * <li><a href="link">Post title</a> (Comment count)</li>
19 $now = current_time('mysql');
20 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_date <'" . $now . "' AND post_status='publish' AND post_password='' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
23 foreach ($arcresults as $arcresult) {
24 $url = get_month_link($arcresult->year, $arcresult->month);
25 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
26 echo get_archives_link($url, $text, '','<h3>','</h3>');
28 $thismonth = zeroise($arcresult->month,2);
29 $thisyear = $arcresult->year;
31 $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status FROM " . $wpdb->posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND post_status='publish' AND post_password='' ORDER BY post_date DESC");
34 echo "<ul class=\"postspermonth\">\n";
35 foreach ($arcresults2 as $arcresult2) {
36 if ($arcresult2->post_date != '0000-00-00 00:00:00') {
37 $url = get_permalink($arcresult2->ID);
38 $arc_title = $arcresult2->post_title;
40 if ($arc_title) $text = strip_tags($arc_title);
41 else $text = $arcresult2->ID;
43 echo "<li>".get_archives_link($url, $text, '');
44 $comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
45 $comments_count = mysql_num_rows($comments);
46 if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' ('.$comments_count.')';
58 * Function BX_get_recent_posts
59 * ------------------------------------------------------
60 * Outputs an unorderd list of the most recent posts.
62 * $current_id this post will be excluded
63 * $limit max. number of posts
66 function BX_get_recent_posts($current_id, $limit)
69 $posts = $wpdb->get_results("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_status='publish' ORDER BY post_date DESC LIMIT " . $limit);
70 foreach ($posts as $post) {
71 $post_title = stripslashes($post->post_title);
72 $permalink = get_permalink($post->ID);
73 if ($post->ID != $current_id) echo "<li><a href=\"" . $permalink . "\">" . $post_title . "</a></li>\n";
79 * Function BX_get_pages
80 * ------------------------------------------------------
81 * Returns the following of all WP pages:
82 * ID, title, name, (content)
84 * $withcontent specifies if the page's content will
88 function BX_get_pages($with_content = '')
91 $query = "SELECT ID, post_title, post_name FROM " . $wpdb->posts . " WHERE post_type='page' OR post_status='static' ORDER BY menu_order ASC";
93 if ($with_content == "with_content") {
94 $query = "SELECT ID, post_title,post_name, post_content FROM " . $wpdb->posts . " WHERE post_type='page' OR post_status='static' ORDER BY menu_order ASC";
96 return $wpdb->get_results($query);
101 * Function BX_excluded_pages()
102 * ------------------------------------------------------
103 * Returns the Blix default pages that are excluded
104 * from the navigation in the sidebar
108 function BX_excluded_pages()
110 $pages = BX_get_pages();
113 foreach ($pages as $page) {
114 $page_id = $page->ID;
115 $page_name = $page->post_name;
116 if ($page_name == "archives" || $page_name == "about" || $page_name == "about_short" || $page_name == "contact") {
117 $exclude .= ", ".$page_id;
120 $exclude = preg_replace("/^, (.*?)/","\\1",$exclude);
127 * Function BX_shift_down_headlines
128 * ------------------------------------------------------
129 * Shifts down the headings by one level (<h5> --> </h6>)
130 * Used for posts in the archive
133 function BX_shift_down_headlines($text)
135 $text = apply_filters('the_content', $text);
136 $text = preg_replace("/h5>/","h6>",$text);
137 $text = preg_replace("/h4>/","h5>",$text);
138 $text = preg_replace("/h3>/","h4>",$text);
144 * Function BX_remove_p
145 * ------------------------------------------------------
146 * Removes the opening <p> and closing </p> from $text
147 * Used for the short about text on the front page
150 function BX_remove_p($text)
152 $text = apply_filters('the_content', $text);
153 $text = preg_replace("/^[\t|\n]?<p>(.*)/","\\1",$text); // opening <p>
154 $text = preg_replace("/(.*)<\/p>[\t|\n]$/","\\1",$text); // closing </p>