PHP
<?php
//Shortcode [catlist parameter="value"]
$custom_field_name = ""; //-- BEARBEITEN!
function catlist_func($atts, $content=null) {
$atts=shortcode_atts(array(
'id' => '0',
'name' => 'default',
'orderby' => 'date',
'order' => 'desc',
'numberposts' => '5',
'date' => 'no',
'author' => 'no'
), $atts);
return list_category_posts($atts);
}
add_shortcode('catlist', 'catlist_func');
function list_category_posts($atts, $custom_field_name){
$output = "<ul class='lcp_catlist'>";
if($atts['name']!='default' && $atts['id']!='0'){
$category='category_name='.$atts['name'];
}else{
$category='category='.$atts['id'];
}
/*I should check this for the next version: ('category__in' => array(2,6))
to allow posts from many categories.
http://codex.wordpress.org/Template_Tags/get_posts#Parameters:_WordPress_2.6.2B */
//Build the query for get_posts()
$catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);
foreach($catposts as $single):
$cust_value = get_post_custom_values($custom_field_name, $single->ID);
if (isset($cust_value[0])) {
$cust_value_data = $cust_value[0];
}else{
$cust_value_data = "";
}
$output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a> ".$cust_value_data;
if($atts['date']=='yes'){
$output.=" - ".$single->post_date;
}
if($atts['author']=='yes'){
$lcp_userdata = get_userdata($single->post_author);
$output.=" - ".$lcp_userdata->user_nicename;
}
$output.="</li>";
endforeach;
$output .= "</ul>";
return $output;
}
function lcp_add_option_page(){
add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
}
//Sidebar Widget:
include('list_cat_posts_widget.php');
//Filters and actions:
add_action('plugins_loaded', 'lcp_load_widget');
?>
Alles anzeigen
Die Variable $custom_field_name oben bearbeiten, sollte ein Custom-Field mit dem Namen angelegt sein fügt er den Inhalt hinter die Titel ein (nicht verlinkt), andernfalls wird nichts erscheinen.