Skip to content

Commit

Permalink
Committing changes on 0.13
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/list-category-posts/trunk@311390 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
fernandobt committed Nov 14, 2010
1 parent 7dc0ab5 commit ca78e21
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 54 deletions.
159 changes: 108 additions & 51 deletions list_cat_posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: List category posts
Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
Description: List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
Version: 0.12
Version: 0.13
Author: Fernando Briano
Author URI: http://picandocodigo.net/
*/
Expand All @@ -25,12 +25,17 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

//Sidebar Widget:

include('list_cat_posts_widget.php');

//Shortcode [catlist parameter="value"]
function catlist_func($atts, $content=null) {
$atts=shortcode_atts(array(
/**
*
* Main plugin function: Gets the shortcode parameters, set defaults, and call the plugin's function.
* @param $atts
* @param $content
*/
function catlist_func($atts, $content = null) {
$atts = shortcode_atts(array(
'id' => '0',
'name' => 'default',
'orderby' => 'date',
Expand All @@ -47,44 +52,33 @@ function catlist_func($atts, $content=null) {
'tags' => '',
'content' => 'no',
'catlink' => 'no',
'comments' => 'no'
'comments' => 'no',
'thumbnail' => 'no'
), $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){
if($atts['name']!='default' && $atts['id']=='0'){
$category = 'category_name=' . $atts['name'];
$category_id = get_cat_ID($atts['name']);
}else{
$category = 'cat=' . $atts['id'];
$category_id = $atts['id'];
}

//Link to the category:
$cat_link_string = '';
if ($atts['catlink'] == 'yes'){
$cat_link = get_category_link($category_id);
$cat_data = get_category($category_id);
$cat_title = $cat_data->name;
$cat_link_string = '<a href=' . $cat_link . ' title="' . $cat_title . '">' . $cat_title . '</a>';
}
//Build the query for get_posts()
$catposts = get_posts($category.'&numberposts=' . $atts['numberposts'] .
'&orderby=' . $atts['orderby'] .
'&order=' . $atts['order'] .
'&exclude=' . $atts['excludeposts'] .
'&tag=' . $atts['tags'] .
'&offset=' . $atts['offset'] );
$lcp_category_id = $atts['id'];
$lcp_category_name = $atts['name'];

//Get the category posts:
$catposts = lcp_category($lcp_category_id, $lcp_category_name, $atts);

//Template code:
$tplFileName = null;
$possibleTemplates = array(
// File locations lower in list override others
STYLESHEETPATH.'/list-category-posts/'.$atts['template'].'.php',
);
foreach($possibleTemplates as $key => $file) {
foreach ($possibleTemplates as $key => $file) {
if (is_readable($file)) {
$tplFileName = $file;
}
Expand All @@ -94,41 +88,96 @@ function list_category_posts($atts){
}else{
if ($cat_link_string != ''){
$lcp_output = '<p><strong>' . $cat_link_string . '</strong></p>';
}else{
} else {
$lcp_output = '';
}
$lcp_output .= '<ul class="lcp_catlist">';//For default ul
foreach($catposts as $single):
$lcp_output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
if($atts['comments'] == yes){
$lcp_output .= ' (' . $single->comment_count . ')';
}
if($atts['date']=='yes'){
$lcp_output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
}
if($atts['author']=='yes'){
$lcp_userdata = get_userdata($single->post_author);
$lcp_output.=" - ".$lcp_userdata->display_name . '<br/>';
}
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);
}
$lcp_output.="</li>";
foreach ($catposts as $single):
$lcp_output .= lcp_display_post($single, $atts);
endforeach;
$lcp_output .= "</ul>";
}
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'];
}

//Link to the category:
$cat_link_string = '';
if ($atts['catlink'] == 'yes'){
$cat_link = get_category_link($category_id);
$cat_data = get_category($category_id);
$cat_title = $cat_data->name;
$cat_link_string = '<a href="' . $cat_link . '" title="' . $cat_title . '">' . $cat_title . '</a>';
}
//Build the query for get_posts()
$catposts = get_posts($lcp_category.'&numberposts=' . $atts['numberposts'] .
'&orderby=' . $atts['orderby'] .
'&order=' . $atts['order'] .
'&exclude=' . $atts['excludeposts'] .
'&tag=' . $atts['tags'] .
'&offset=' . $atts['offset'] );
return $catposts;
}

function lcp_display_post($single, $atts){
$lcp_output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
if ($atts['comments'] == yes){
$lcp_output .= ' (';
$lcp_output .= lcp_comments($single);
$lcp_output .= ')';
}
if ($atts['date']=='yes'){
$lcp_output .= lcp_showdate($single);
}
if ($atts['author']=='yes'){
$lcp_output .= " - ".lcp_showauthor($single) . '<br/>';
}
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['thumbnails']=='yes'){
$lcp_output .= lcp_thumbnails($single);
}
$lcp_output.="</li>";
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){
return ' - ' . get_the_time($atts['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(']]>', ']]&gt', $lcp_content); // added to parse shortcodes
return '<p>' . $lcp_content . '</p>';
}


function lcp_excerpt($single){
if($single->post_excerpt){
return '<p>' . $single->post_excerpt . '</p>';
Expand All @@ -144,8 +193,16 @@ function lcp_excerpt($single){
return '<p>' . $lcp_excerpt . '</p>';
}


function lcp_thumbnails($single){
$lcp_thumbnails = '';
if ( has_post_thumbnail($single->ID) ) {
$lcp_thumbnails = get_the_post_thumbnail($single->ID);
}
return $lcp_thumbnails;
}

/** TODO - These are the todo's for a 1.0 release:
* -Images (preview or thumbnail, whatever, I have to dig into this)
* -Pagination
* -Simplify template system
* -i18n
Expand Down
11 changes: 8 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: fernandobt
Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
Tags: list, categories, posts, cms
Requires at least: 2.8
Tested up to: 3.0
Stable tag: 0.12
Tested up to: 3.0.1
Stable tag: 0.13

== Description ==
List Category Posts is a simple WordPress plugin which allows you to list posts from a category into a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can use [catlist] as many times as needed with different arguments.
Expand Down Expand Up @@ -67,7 +67,7 @@ If you use both arguments (wrong!), List Category Posts will show the posts from

* **author** - Display the post's author next to the title. Default is 'no', use author=yes to activate it.

* **dateformat** - Format of the date output. Default is get_option('date_format')
* **dateformat** - Format of the date output. Default is get_option('date_format'). Check http://codex.wordpress.org/Formatting_Date_and_Time for possible formats.

* **template** - File name of template from templates directory without extension. Example: For 'template.php' value is only 'template'. Default is 'default' that means template in code of plugin not in template file, that's an unordered list (ul html tag) with a CSS class: 'lcp_catlist'

Expand All @@ -83,6 +83,8 @@ If you use both arguments (wrong!), List Category Posts will show the posts from

* **comments** - Show comments count for each post. Default is 'no'. Ex: [catlist comments=yes].

* **thumbnails** - Show post thumbnails (http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/). Default is 'no'. Ex: [catlist thumbnails=yes].

Your comments and feedback are welcome at: http://foro.picandocodigo.net/viewforum.php?f=28

**New Code is welcome too** :D
Expand All @@ -105,6 +107,9 @@ Template system has changed. Custom templates should be stored in wordpress them

== Changelog ==

= 0.13 =
* Show post thumbnails, should be tested, feedback on styling is welcome. Thanks to Sebastian from http://www.avantix.com.ar/

= 0.12 =
* Added comments count.
* Updated readme file
Expand Down

0 comments on commit ca78e21

Please sign in to comment.