where XX is the number of characters you would like to limit the post titles in the recent posts list. Example: oden_wp_get_archives('type=postbypost&limit=20&format=html&before=o &title_limit=36&oden_offset=10'); ?> */ function utf8_substr($str,$from,$len){ # utf8 substr # www.yeap.lv return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',$str); } function oden_excerpt($text, $chars) { $origLen = strlen(utf8_decode($text)); if($origLen>$chars) { $text = utf8_substr($text,0,$chars); $text = strip_tags($text) . " .."; } return ($text); } /* link navigation based on hack by Orien http://icecode.com/ */ function oden_get_archives_link($url, $text, $format = 'html', $before = '', $after = '', $title_limit = '') { //$text = wptexturize($text); //$title_text = attribute_escape($text); $title_text = wp_specialchars($text, 1); if ( '' == $title_limit ) { $title_limit = '500'; } if ('link' == $format) return "\t\n"; elseif ('option' == $format) return "\t\n"; elseif ('html' == $format) return "\t
  • $before" . oden_excerpt($text, $title_limit) . "$after
  • \n"; else // custom return "\t$before" . oden_excerpt($text, $title_limit) . "$after\n"; } function oden_wp_get_archives($args = '') { global $wp_locale, $wpdb, $page_id, $paged; if ( is_array($args) ) $r = &$args; else parse_str($args, $r); $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false); $r = array_merge($defaults, $r); if ( !isset($r['title_limit']) ) $r['title_limit'] = ''; if ( !isset($r['oden_offset']) ) { $r['oden_offset'] = ''; } else { if (is_paged() || is_home()) $r['limit'] = $r['limit'] + $paged*$r['oden_offset']; } extract($r); if ( '' == $type ) $type = 'monthly'; if ( '' != $limit ) { $limit = (int) $limit; $limit = ' LIMIT '.$limit; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if ( !$archive_date_format_over_ride ) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } $add_hours = intval(get_option('gmt_offset')); $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours)); if ( 'monthly' == $type ) { $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_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); if ( $arcresults ) { $afterafter = $after; foreach ( $arcresults as $arcresult ) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); if ( $show_post_count ) $after = ' ('.$arcresult->posts.')' . $afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('yearly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts WHERE post_type ='post' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_year_link($arcresult->year); $text = sprintf('%d', $arcresult->year); if ($show_post_count) $after = ' ('.$arcresult->posts.')' . $afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ( 'daily' == $type ) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit); if ( $arcresults ) { $afterafter = $after; foreach ( $arcresults as $arcresult ) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($show_post_count) $after = ' ('.$arcresult->posts.')'.$afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ( 'weekly' == $type ) { $start_of_week = get_option('start_of_week'); $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC" . $limit); $arc_w_last = ''; $afterafter = $after; if ( $arcresults ) { foreach ( $arcresults as $arcresult ) { if ( $arcresult->week != $arc_w_last ) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($show_post_count) $after = ' ('.$arcresult->posts.')'.$afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) { ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC "; $arcresults = $wpdb->get_results("SELECT DISTINCT ID, post_type, post_status, post_title, post_date FROM $wpdb->posts, $wpdb->post2cat WHERE post_type = 'post' AND post_status = 'publish' AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id != '11' ORDER BY $orderby $limit"); if ( $arcresults ) { $oden_postnum=0; foreach ( $arcresults as $arcresult ) { $oden_postnum++; //echo $oden_offset . ' '; //echo $paged . ' '; //echo $r['limit'] . ' '; //echo $oden_postnum . ' '; if ( ($arcresult->post_date != '0000-00-00 00:00:00') && $oden_postnum > $oden_offset*$paged ) { $url = get_permalink($arcresult->ID); $arc_title = $arcresult->post_title; if ( $arc_title ) $text = strip_tags($arc_title); else $text = $arcresult->ID; echo oden_get_archives_link($url, $text, $format, $before, $after, $title_limit); } } } } } ?>