function sideblog($asidecategory = '') { global $wpdb, $sb_defaultformat, $sb_defaultposts; $limit = 5; $sideblog_options = get_option('sideblog_options'); if (!isset($asidecategory) || empty($asidecategory)) { echo "Aside category not selected. Please provide a category slug if you're using non-dynamic sidebar."; return; } if (!$asidecategory) { $asidecount = count($sideblog_options['setaside']); if ($asidecount < 1) { echo "No aside category selected. Please select an aside category in Options » Sideblog Panel."; return; } $asideid = ''; if ($sideblog_options['setaside']) { foreach ($sideblog_options['setaside'] as $aside) { if ($asideid != '') { break; } $asideid = $aside; } } } else { $asideid = $wpdb->get_var("SELECT cat_ID FROM " . $wpdb->categories . " WHERE category_nicename='" . $asidecategory . "'"); if ($sideblog_options['setaside']) { if (!in_array($asideid, $sideblog_options['setaside'])) { echo "Aside category not selected."; return; } } } $asidecategory = $asideid; $limit = $sideblog_options['numentries'][$asideid]; if (!$limit) { $limit = $sb_defaultposts; } $displayformat = stripslashes($sideblog_options['displayformat'][$asideid]); if (!$displayformat) { $displayformat = $sb_defaultformat; } $now = current_time('mysql'); $sideblog_contents = $wpdb->get_results("SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_title, {$wpdb->posts}.post_content, {$wpdb->posts}.post_date FROM {$wpdb->posts}, {$wpdb->post2cat} WHERE {$wpdb->posts}.ID = {$wpdb->post2cat}.post_id AND {$wpdb->post2cat}.category_id = {$asidecategory} AND {$wpdb->posts}.post_status ='publish' AND {$wpdb->posts}.post_password ='' AND {$wpdb->posts}.post_date < '" . $now . "' ORDER BY {$wpdb->posts}.post_date DESC LIMIT " . $limit); $patterns[] = "%title%"; $patterns[] = "%content%"; $patterns[] = "%permalink%"; $patterns[] = "%title_url%"; $patterns[] = "%postdate%"; $patterns[] = "%postdate_url%"; $patterns[] = "%excerpt%"; preg_match("/\\%excerpt\\_\\d+\\%/", $displayformat, $matches); $patterns[] = $matches[0]; preg_match("/\\d+/", $matches[0], $excerptcut); if ($sideblog_contents) { foreach ($sideblog_contents as $sideblog_content) { $permalink = get_permalink($sideblog_content->ID); //apply content filters to insert p / br $mycontent = apply_filters('the_content', $sideblog_content->post_content); $excerpt = sideblog_excerpt($sideblog_content->post_content, 15); $excerpt2 = sideblog_excerpt($sideblog_content->post_content, $excerptcut[0]); $replacements[] = $sideblog_content->post_title; $replacements[] = $mycontent; $replacements[] = "<a href=\"" . $permalink . "\">#</a>"; $replacements[] = "<a href=\"" . $permalink . "\" title=\"" . $sideblog_content->post_title . "\">" . $sideblog_content->post_title . "</a>"; $replacements[] = $sideblog_content->post_date; $replacements[] = "<a href=\"" . $permalink . "\">" . $sideblog_content->post_date . "</a>"; $replacements[] = $excerpt; $replacements[] = $excerpt2; $output = str_replace($patterns, $replacements, $displayformat); if (preg_match_all("/\\%(\\w)\\%/", $output, $matches)) { foreach ($matches[1] as $match) { $output = str_replace("%" . $match . "%", date($match, strtotime($sideblog_content->post_date)), $output); } } if (preg_match_all("/\\%url\\%([^\\%]*)\\%url\\%/", $output, $matches)) { foreach ($matches[1] as $match) { $output = str_replace("%url%" . $match . "%url%", "<a href=\"" . $permalink . "\">" . $match . "</a>", $output); } } unset($matches); if (function_exists('Markdown')) { $output = Markdown($output); } echo $output; unset($replacements); } } }
function sideblog($asidecategory=''){ global $wpdb, $sb_defaultformat,$sb_defaultposts; $limit = 5; $sideblog_options = get_option('sideblog_options'); if(!isset($asidecategory) || empty($asidecategory)) { echo "Aside category not selected. Please provide a category slug if you're using non-dynamic sidebar."; return; } if(!$asidecategory){ $asidecount = count($sideblog_options['setaside']); if($asidecount < 1){ echo "No aside category selected. Please select an aside category in Options » Sideblog Panel."; return; } $asideid = ''; if(isset($sideblog_options['setaside']) && !empty($sideblog_options['setaside'])){ foreach($sideblog_options['setaside'] as $aside){ if($asideid!=''){ break; } $asideid = $aside; } } } else { $asideid = $wpdb->get_var("SELECT term_id FROM " . $wpdb->terms . " WHERE slug='" . $asidecategory . "'"); if(isset($sideblog_options['setaside']) && !empty($sideblog_options['setaside'])){ if(!in_array($asideid,$sideblog_options['setaside'])){ echo "Aside category not selected."; return; } } else { echo "Aside category not selected."; return; } } $asidecategory = $asideid; $limit = $sideblog_options['numentries'][$asideid]; if(!$limit){ $limit = $sb_defaultposts; } $displayformat = stripslashes($sideblog_options['displayformat'][$asideid]); if(!$displayformat){ $displayformat = $sb_defaultformat; } $now = current_time('mysql'); $wp_query = new WP_Query(); $wp_query->set('category__in', array($asideid)); $wp_query->set('posts_per_page', $limit); $wp_query->set('category__not_in',array()); $sideblog_contents = $wp_query->get_posts(); $patterns[] = "%title%"; $patterns[] = "%content%"; $patterns[] = "%permalink%"; $patterns[] = "%title_url%"; $patterns[] = "%postdate%"; $patterns[] = "%postdate_url%"; $patterns[] = "%excerpt%"; preg_match("/\%excerpt\_\d+\%/",$displayformat,$matches); $patterns[] = $matches[0]; preg_match("/\d+/",$matches[0],$excerptcut); if($sideblog_contents){ if($sideblog_options['order'][$asideid] == 'ASC'){ $sideblog_contents = array_reverse($sideblog_contents); } foreach($sideblog_contents as $sideblog_content){ $permalink = get_permalink($sideblog_content->ID); $excerpt = sideblog_excerpt($sideblog_content->post_content,15); $excerpt2 = sideblog_excerpt($sideblog_content->post_content,$excerptcut[0]); $sideblog_content = apply_filters('sideblog_entry', $sideblog_content); $replacements[] = $sideblog_content->post_title; $replacements[] = wpautop($sideblog_content->post_content); $replacements[] = "<a href=\"" . $permalink . "\">#</a>"; $replacements[] = "<a href=\"" . $permalink . "\" title=\"" . $sideblog_content->post_title . "\">" . $sideblog_content->post_title . "</a>"; $replacements[] = $sideblog_content->post_date; $replacements[] = "<a href=\"" . $permalink . "\">" . $sideblog_content->post_date . "</a>"; $replacements[] = $excerpt; $replacements[] = $excerpt2; $output = str_replace($patterns,$replacements,$displayformat); if(preg_match_all("/\%(\w)\%/",$output,$matches)){ foreach($matches[1] as $match){ $output = str_replace("%" . $match . "%",date($match,strtotime($sideblog_content->post_date)),$output); } } if(preg_match_all("/\%url\%([^\%]*)\%url\%/",$output,$matches)){ foreach($matches[1] as $match){ $output = str_replace("%url%" . $match . "%url%","<a href=\"" . $permalink . "\">" . $match . "</a>",$output); } } unset($matches); if(function_exists('Markdown')){ $output = Markdown($output); } echo $output; unset($replacements); } } }