Edit Settings. Version: 1.4 Author: April Hodge Silver Author URI: http://springthistle.com/ License: GPL2 Copyright 2010 April Hodge Silver (email : april@springthistle.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. 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 */ /* * ahscp_callposts_handler() * gets the post_content & title of the most recent published post in given category * to be used via shortcode only [ahscp_callposts] * @param string shortcode attributes * @returns string with post title and content */ function ahscp_callposts_handler($atts) { $out = ''; global $post; extract(shortcode_atts(array( 'type' => null, 'category' => null, 'custom_field'=>null, 'title'=>null, 'numberposts'=>1, 'class'=>'post', 'sidebox'=>null, 'sideboxsize'=>'small', 'content_style'=>null, 'separator'=>', ', 'cols'=>1, 'col_item_height'=>260, 'col_item_width'=>320, 'showthumb'=>false, 'order'=>'ASC', 'dateformat'=>null, ), $atts)); $catids = ahscp_get_cats_array(); if (empty($type)) $type = $category; // for backwards compatibility if ($type == null) { $out = ahscp_get_needs_cat_alert($catids); } else { // order by default or by custom field? // let shortcode override options default if (empty($custom_field)) $custom_field = get_option('ahscp_customfield'); if (empty($title)) $title = get_option('ahscp_titletype'); if (empty($title)) $title = 'h3'; if (empty($content_style)) $content_style = get_option('ahscp_contentstyle'); if ($dateformat != '-' ) $dateformat = get_option('ahscp_dateformat'); else $dateformat = null; // if $category/$type has commas, turn it into a list of IDs if (ereg(',',$type)) { $cnames = split(",[ ]*",$type); $category_ids = ""; foreach ($cnames as $n) $category_ids .= $catids[$n].','; } else { $category_ids = $catids[$type]; } // get two lists of posts. the first ordered by the custom field, the second those without the custom field if (!empty($custom_field)) $posts1 = get_posts('numberposts='.$numberposts.'&category='.$category_ids.'&meta_key=event_date&orderby=meta_value&order='.$order); $posts2 = get_posts('numberposts='.$numberposts.'&category='.$category_ids); if (!empty($custom_field)) { list($out1,$used_ids) = ahscp_spit_posts($posts1,$title,$dateformat,$class,$content_style,$separator,$showthumb,$col_item_height); list($out2,$discard) = ahscp_spit_posts($posts2,$title,$dateformat,$class,$content_style,$separator,$showthumb,$col_item_height,$used_ids); $out = $out1.$out2; } else { list($out,$discard) = ahscp_spit_posts($posts2,$title,$dateformat,$class,$content_style,$separator,$showthumb,$col_item_height); } } if ($sidebox!=null) { $sizes = array('small'=>'210','medium'=>'300','large'=>'350','xlarge'=>'425'); $out = '
');
}
if ($content_style=='excerpt') {
if (!empty($post->post_excerpt)) $excerpt = $post->post_excerpt;
else $excerpt = get_the_excerpt();
$out .= '
'.$excerpt.' Read on »
'; } else $out .= $content; $out .= '[ahs_callposts category="'.$cat.'"]You can choose the default settings for the shortcode here. These settings apply to every instance of the shortcode on the site, old or new, unless the instance itself overrides this setting.
category | No default. Required. Enter the slug of the category you'd like to use. Separate multiple category slugs with commas. |
custom_field | Default is the option set above, if not empty. Otherwise, ignored. |
title | Default = h3. Can be any HTML tag name (b, i, u, h4, etc) |
dateformat | Default is to not show the date. If you enter a dateformat for an instance of the shortcode (or above as a default for the whole site), the date will be shown preceding the title (if content_type is not title). Formatting tips. |
numberposts | Default = 1. This is the number of posts that are called in. To have no limit, use -1. |
class | Default = post. You can choose another class, for example, one controlled in your own theme's stylesheet, instead. |
sidebox | Empty and ignored by default. If set to true, puts the posts in a box floating at the right side of the page. |
sideboxsize | Empty and ignored by default. Only used if sidebox is set to true. Then, default = "small" which translates to a width of 210px. Other options are: medium (300px), large (350px), xlarge (425px). Height of the sidebox is determined by the length of the content. |
content_style | Default = option set above. To override the default, set to one of these other options in the shortcode: excerpt, title. |
separator | Default is a comma (,). Only used if content_style is set to title. |
cols | Default = 1. Only other option is 2. |
col_item_width | Empty and ignored by default. Only used if cols is set to 2. Then the default = 320, which is a pixel measurement. |
col_item_height | Empty and ignored by default. Only used if cols is set to 2. Then the default = 260, which is a pixel measurement. |
showthumb | Empty and ignored by default. If set to true, then the post thumbnail is displayed before the post (You choose the post thumbnail at the bottom right on the Edit Post page). The image has the class attachment-thumbnail, so you can style it. |
order | Default is ASC. Can be set to DESC. Used only when a custom field is set. |
If you want to call the 5 most recent posts in the category into a page, place this shortcode on the page:
[ahs_callposts category="" numberposts="5"]
If you want to call all posts in the category into a page but only list linkable titles with hard returns between them, place this shortcode on the page:
[ahs_callposts category="" numberposts="-1" content_style="title" separator="<br />"]
If you want to call the 6 most recent posts in the category into a page in two columns 220px wide with a thumbnail image:
[ahs_callposts category="" numberposts="6" cols="2" showthumb="true" col_item_width="220"]