archivist
dann frag ich mal nach den einstellungen für archivist:
PHP
//----------------------------EDIT HERE-------------------------------------------------
$archivist_settings['number_of_posts'] = 3;
$archivist_settings['random'] = false;//selected posts should be sorted randomly or by time?
$archivist_settings['frontpage_position'] = 1;//indexed from 0!
$archivist_settings['from_categories'] = "";//list of IDs of categories separated by commas. "" (empty string) means that this rule is not used
$archivist_settings['older_than'] = 30;//days. -1 means that this rule is not used
$archivist_settings['newer_than'] = -1;//days. -1 means that this rule is not used
$archivist_settings['keep_the_limit_of_posts_per_page'] = false;//if 'true' then the 'random posts' will be added to the number of posts already shown on the front page
//if 'false' then last post(s) will be thrown away and random posts will be added where they are supposed to be
//the point is that then you'll have a lack of post(s) between the first and second page...:(
/*
if you have installed Polyglot (http://fredfred.net/skriker/index.php/polyglot)
you can use different language versions in $archivist_settings['title']
example: $archivist_settings['title'] = '<lang_cs>Z archivu: </lang_cs><lang_en>From the Archive: </lang_en>%title';
*/
//%title will be replace with original post title
$archivist_settings['title'] = 'Das Neuste: %title';
/*===============for advanced users=======================
you can use something more sophisticated to specify 'older_than' and 'newer_than' values
$archivist_settings['newer_than'] = ( time() - mktime(0,0,0,5,1,2005) )/ (60*60*24);
this example allows only posts newer than 1st of May 2005
hint from PHP manual:
mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
*/
//###########STOP EDITING HERE#######################
add_filter('the_posts','archivist_main');
function archivist_main($posts){
global $archivist_settings, $wpdb, $wp_query, $paged;
if(!$wp_query->is_home || $paged > 1 || $wp_query->query_vars['paged'] > 1)//random post should be only on the front page
{
return $posts;
}
//co-operation with Polyglot
if(function_exists(lang_picker_respect_more)){
$archivist_settings['title'] = lang_picker_respect_more($archivist_settings['title']);
}
$my_posts = array();
$j = count($posts);//trick to keep the limit of posts per page
for($i = 0; $i <= $j; $i++){
$post = $posts[$i];
if($i == $archivist_settings['frontpage_position'] ){
$oldest_post = $posts[count($posts)-1]->post_date_gmt;//to select posts that are not on the page already
$now = current_time('mysql', 1);
//let's start with query
$query = "SELECT * FROM $wpdb->posts ";
//if you want to select only from defined categories
if($archivist_settings['from_categories'] != ""){
$query .=",$wpdb->post2cat ";
}
$query .= " WHERE post_status = 'publish' AND post_date_gmt <= '$oldest_post' ";
//do we have an older_than rule?
if($archivist_settings['older_than'] > -1)
$query .= "AND post_date_gmt <= DATE_SUB('$now', INTERVAL {$archivist_settings['older_than']} DAY) ";
//do we have a newer_than rule with reasonable value?
if($archivist_settings['newer_than'] > -1 && $archivist_settings['newer_than'] >= $archivist_settings['older_than'] )
$query .= "AND post_date_gmt >= DATE_SUB('$now', INTERVAL {$archivist_settings['newer_than']} DAY) ";
//select only from defined categories
if($archivist_settings['from_categories'] != ""){
$query .="AND post_ID = ID AND (";
$tok = strtok($archivist_settings['from_categories'], ",");
$first = true;
while ($tok) {
$foo = trim($tok);
if(!$first){ $query .=' OR ';}
else {$first = false;}
$query .="category_ID = '$foo' ";
$tok = strtok(",");
}
$query .= ') ';
}
//select randomly or not?
if($archivist_settings['random']){
$orderby = 'rand()';
}
else {
$orderby = 'post_date_gmt DESC';
}
//some other plugins could show their power here
$orderby = apply_filters('posts_orderby', $orderby);
$query .= "ORDER BY $orderby ";
$query .= " LIMIT {$archivist_settings['number_of_posts']}";
if($drafts = $wpdb->get_results($query)){
foreach($drafts as $draft){
$draft->post_title = str_replace("%title", $draft->post_title, $archivist_settings['title'] );
$my_posts[] = $draft;
}
//we don't want to exceed the limit of posts per page
if($archivist_settings['keep_the_limit_of_posts_per_page']){
$j -= count($drafts);
}
}
}
if($i < $j){
$my_posts[] = $post;
}
}
update_post_caches($my_posts) ;
return $my_posts;
}
?>
Alles anzeigen