'0', 'name' => 'default', 'orderby' => 'date', 'order' => 'desc', 'numberposts' => '5', 'date' => 'no', 'author' => 'no', 'dateformat' => get_option('date_format'), 'template' => 'default', 'excerpt' => 'no', 'exclude' => '0', 'excludeposts' => '0', 'offset' => '0', 'tags' => '', 'content' => 'no', 'catlink' => 'no', 'comments' => 'no', 'thumbnail' => 'no', 'post_type' => '', 'post_parent' => '0', 'class' => 'lcp_catlist' ), $atts); return list_category_posts($atts); } /* Add the shortcode to WordPress */ add_shortcode('catlist', 'catlist_func'); /** * Main function, this is where the flow goes and calls auxiliary functions * @param array $atts */ function list_category_posts($atts){ $lcp_category_id = $atts['id']; $lcp_category_name = $atts['name']; //Get the category posts: $catposts = lcp_category($lcp_category_id, $lcp_category_name, $atts); $lcp_output = ''; //Link to the category: if ($atts['catlink'] == 'yes'){ $cat_link = get_category_link($lcp_category_id); $cat_title = get_cat_name($lcp_category_id); $lcp_output .= '' . $cat_title . ''; } //Template code: $tplFileName = null; $possibleTemplates = array( // File locations lower in list override others WP_PLUGIN_DIR.'/list-category-posts/templates/'.$atts['template'].'.php', ); foreach ($possibleTemplates as $key => $file) { if (is_readable($file)) { $tplFileName = $file; } } if ((!empty($tplFileName)) && (is_readable($tplFileName))) { require($tplFileName); }else{ // Default template $lcp_output .= '"; } return $lcp_output; } /** * Get the categories * @param string $lcp_category_id * @param string $lcp_category_name */ function lcp_category($lcp_category_id, $lcp_category_name, $atts){ if($lcp_category_name != 'default' && $lcp_category_id == '0'){ $lcp_category = 'category_name=' . $atts['name']; $category_id = get_cat_ID($atts['name']); }else{ $lcp_category = 'cat=' . $atts['id']; $category_id = $atts['id']; } //Build the query for get_posts() $lcp_query = $lcp_category.'&numberposts=' . $atts['numberposts'] . '&orderby=' . $atts['orderby'] . '&order=' . $atts['order'] . '&exclude=' . $atts['excludeposts'] . '&tag=' . $atts['tags'] . '&offset=' . $atts['offset']; if($atts['post_type']): $lcp_query .= '&post_type=' . $atts['post_type']; endif; if($atts['post_parent']): $lcp_query .= '&post_parent=' . $atts['post_parent']; endif; return get_posts($lcp_query); } function lcp_display_post($single, $atts){ $lcp_output .= '
  • ' . $single->post_title . ''; if ($atts['comments'] == yes){ $lcp_output .= ' ('; $lcp_output .= lcp_comments($single); $lcp_output .= ')'; } if ($atts['date']=='yes'){ $lcp_output .= lcp_showdate($single, $atts['dateformat']); } if ($atts['author']=='yes'){ $lcp_output .= " - ".lcp_showauthor($single) . '
    '; } if ($atts['content']=='yes' && $single->post_content){ $lcp_output.= lcp_content($single); // line tweaked to output filtered content } if ($atts['excerpt']!='no' && !($atts['content']=='yes' && $single->post_content) ){ $lcp_output .= lcp_excerpt($single); } if ($atts['thumbnail']=='yes'){ $lcp_output .= lcp_thumbnail($single); } $lcp_output.="
  • "; return $lcp_output; } function lcp_comments($single){ return $single->comment_count; } function lcp_showauthor($single){ $lcp_userdata = get_userdata($single->post_author); return $lcp_userdata->display_name; } function lcp_showdate($single, $dateformat){ return ' - ' . get_the_time($dateformat, $single);//by Verex, great idea! } function lcp_content($single){ $lcp_content = apply_filters('the_content', $single->post_content); // added to parse shortcodes $lcp_content = str_replace(']]>', ']]>', $lcp_content); // added to parse shortcodes return '

    ' . $lcp_content . '

    '; } function lcp_excerpt($single){ if($single->post_excerpt){ return '

    ' . $single->post_excerpt . '

    '; } $lcp_excerpt = strip_tags($single->post_content); if ( post_password_required($post) ) { $lcp_excerpt = __('There is no excerpt because this is a protected post.'); return $lcp_excerpt; } if (strlen($lcp_excerpt) > 255) { $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...'; } return '

    ' . $lcp_excerpt . '

    '; } function lcp_thumbnail($single){ $lcp_thumbnail = ''; if ( has_post_thumbnail($single->ID) ) { $lcp_thumbnail = get_the_post_thumbnail($single->ID); } return $lcp_thumbnail; } /** TODO - These are the todo's for a 1.0 release: * -Pagination * -Simplify template system * -i18n */ ?>