Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sunriseweb
Created November 28, 2011 19:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunriseweb/1401538 to your computer and use it in GitHub Desktop.
Save sunriseweb/1401538 to your computer and use it in GitHub Desktop.
List category posts - List category template - TwentyTen theme
<?php
/*
Plugin Name: List Category Posts - Template
Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
Description: Template file for List Category Post Plugin for Wordpress which is used by plugin by argument template=value.php
Version: 0.9
Author: Radek Uldrych & Fernando Briano
Author URI: http://picandocodigo.net http://radoviny.net
Modified by: Brad Trivers
Modified URI: http://sunriseweb.ca
Modified Description: Create template to work specifically with TwentyTen theme to list posts
*/
/* Copyright 2009 Radek Uldrych (email : verex@centrum.cz), Fernando Briano (http://picandocodigo.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* The format for templates changed since version 0.17.
* Since this code is included inside CatListDisplayer, $this refers to
* the instance of CatListDisplayer that called this file.
*/
/* This is the string which will gather all the information.*/
$lcp_display_output = '';
// Show category link:
$lcp_display_output .= $this->get_category_link('strong');
//Add 'starting' tag. Here, I'm using an unordered list (ul) as an example:
$lcp_display_output .= '<ul class="lcp_catlist" style="margin-left: 0;">';
/**
* Posts loop.
* The code here will be executed for every post in the category.
* As you can see, the different options are being called from functions on the
* $this variable which is a CatListDisplayer.
*
* The CatListDisplayer has a function for each field we want to show.
* So you'll see get_excerpt, get_thumbnail, etc.
* You can now pass an html tag as a parameter. This tag will sorround the info
* you want to display. You can also assign a specific CSS class to each field.
*/
$date_format = get_option('date_format');
foreach ($this->catlist->get_categories_posts() as $single):
//Start a List Item for each post:
$lcp_display_output .= "<li>";
$titletext = $this->get_post_title($single);
$thePermalink = get_permalink($single->ID);
$lcp_display_output .= '<h2 class="entry-title" style="font-size: 15px;">'.$titletext.'</h2>';
$lcp_display_output .= '<div class="entry-meta">';
//Show the title and link to the post:
//Show author
$authorPostsUrl = get_author_posts_url($single->post_author);
$authorInfo = get_userdata($single->post_author);
$lcp_display_output .= 'Posted on <span class="sep"><a href="'.$thePermalink.'" target="_blank">'. get_the_time($date_format, $single) .'</a></span>';
$lcp_display_output .= '<br />by <a href="'.$authorPostsUrl.'">'.$authorInfo->display_name.'</a>';
//Show comments:
$lcp_display_output .= ' | <a href="'.$thePermalink.'#respond" target="_blank">' . $single->comment_count . ' comments</a><br />';
$lcp_display_output .= '</div><!-- end .entry-meta -->';
//Custom fields:
$lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);
/**
* Post content - Example of how to use tag and class parameters:
* This will produce:<div class="lcp_excerpt">The content</div>
*/
// $lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');
/**
* Post content - Example of how to use tag and class parameters:
* This will produce:<p class="lcp_content">The content</p>
*/
$moreTag = get_extended($single->post_content);
$truncate = apply_filters('the_content', $moreTag['main']);
$lcp_display_output .= '<div class="entry-content" style="padding-top: 10px;">';
//Post Thumbnail
$thumbnail = get_the_post_thumbnail($single->ID, 'thumbnail');
if( $thumbnail <> '' ) {
$lcp_display_output .= '<a href="'.$thePermalink.'" class="alignleft" target="_blank">'.$thumbnail.'</a>';
}
$lcp_display_output .= $truncate;
if ($truncate != $single->post_content) {
// $lcp_display_output .= '<p>[<a href="'.$thePermalink.'" target="_blank">read more</a>]</p>';
$lcp_display_output .= '<p><a href="'.$thePermalink.'" target="_blank" class="more-link">'.__( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ).'</a></p>';
}
$lcp_display_output .= '</div>';
$lcp_display_output .= '<div class="entry-meta">';
//Show categories:
$categoryList = "";
$post_categories = get_the_category($single->ID);
foreach($post_categories as $category) {
$catLink = get_category_link($category->cat_ID);
$categoryList .= '<a href="'.$catLink.'" target="_blank">'.$category->cat_name.'</a>, ';
}
$lcp_display_output .= 'Posted in '.substr($categoryList,0,strlen($categoryList)-2);
$posttags = get_the_tags($single->ID);
if ($posttags) {
foreach($posttags as $tag) {
$tagList .= '<a href="'.get_tag_link($tag->term_id).'" target="_blank">'.$tag->name.'</a>, ';
}
}
$lcp_display_output .= ' | Tagged '.substr($tagList,0,strlen($tagList)-2);
// $lcp_display_output .= '</p><!-- end .entry-meta -->';
$lcp_display_output .= '</div><!-- end .entry-meta -->';
$lcp_display_output .= '<div class="clear"><hr style="margin: 7px 0 0 0; padding: 0;" /></div>';
//Close li tag
$lcp_display_output .= '</li>';
endforeach;
$lcp_display_output .= '</ul>';
$this->lcp_output = $lcp_display_output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment