Edit Settings. Version: 1.1 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, 'showthumb'=>false, 'order'=>'ASC', ), $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'); // 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='.$catids[$type].'&meta_key=event_date&orderby=meta_value&order='.$order); $posts2 = get_posts('numberposts='.$numberposts.'&category='.$catids[$type]); if (!empty($custom_field)) { list($out1,$used_ids) = ahscp_spit_posts($posts1,$title,$class,$content_style,$separator,$showthumb,$col_item_height); list($out2,$discard) = ahscp_spit_posts($posts2,$title,$class,$content_style,$separator,$showthumb,$col_item_height,$used_ids); $out = $out1.$out2; } else { list($out,$discard) = ahscp_spit_posts($posts2,$title,$class,$content_style,$separator,$showthumb,$col_item_height); } } if ($sidebox!=null) { $sizes = array('small'=>'210','medium'=>'300','large'=>'350','xlarge'=>'425'); $out = '
'.$out.'
'; } if ($cols > 1) { $style = ''; $out = $style.'
'.$out.'
 
'; } return $out; } /* * creates a string with post title and content, in a div * used by ahscp_callposts_handler * @param array of wordpress posts * @param HTML object to use for the title * @param name of class to apply to div * @param optional array of post IDs to exclude * @returns string with post title and content for all posts in the array */ function ahscp_spit_posts($posts,$title,$class,$content_style,$separator,$showthumb,$col_item_height,$exclude=array()) { $used_ids = array(); $out = ''; global $more; foreach($posts as $post) : setup_postdata($post); $more = 0; if (!in_array($post->ID,$exclude)) { if ($content_style != 'title') { $content = get_the_content('Read more »'); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = ereg_replace('Read more »<\/a>','Read more »',$content); $out .= '
'; $out .= '<'.$title.'>'; $out .= $post->post_title; if ($url = get_edit_post_link($post->ID)) $out .= ' Edit'; $out .= ''; if ($showthumb==true) { $out .= get_the_post_thumbnail($post->ID, 'thumbnail'); $content = strip_tags($content,'



'); } 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 .= '
'; } else { $out .= ''.$post->post_title.''.$separator; } $used_ids[]=$post->ID; } endforeach; $toreturn = array($out,$used_ids); return $toreturn; } add_shortcode('ahs_callposts', 'ahscp_callposts_handler'); /* * ahscp_get_cats_array() * gets an array of categories ID=>NAME * @returns the array of categories */ function ahscp_get_cats_array() { global $wpdb; $sql = "SELECT tt.term_id, t.slug FROM ".$wpdb->prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE tt.taxonomy LIKE 'category' AND tt.term_id=t.term_id ORDER BY t.slug"; $result = $wpdb->get_results($sql); $catids=array(); foreach ($result as $i) { $catids[$i->slug]=$i->term_id; } return $catids; } /* * ahscp_get_needs_cat_alert() * returns a string with a list of category slugs * @param array of catids ID=>Name * @returns the array of categories */ function ahscp_get_needs_cat_alert($catids) { $out = ''; $out .= '
This shortcode requires a category name. Your choices are:'; $out .= '
    '; foreach (array_keys($catids) as $cat) $out .= '
  • '.$cat.'
  • '; $out .= '
For example: [ahscp_callposts category="'.$cat.'"]
'; return $out; } /* set up options page */ function ahscp_options() { add_submenu_page('options-general.php', 'April\'s Call Posts', 'April\'s Call Posts', 8, basename(__FILE__), 'ahscp_options_page'); } /** * Build up all the params for the button */ function ahscp_options_page() { ?>

Settings for April's Call Posts

You can choose the default settings for the shortcode here. These can be overridden by any given instance of the shortcode.


The shortcode automatically orders posts by most-recent-first. If you'd like them to be ordered by a custom field, enter the name of the custom field here. You can override this default setting in any individual use of the shortcode by including the option custom_field.

This is the HTML tag used for post titles in the shortcode. You can override this default setting in any individual use of the shortcode by including the option title.

This controls whether and how each post's content is displayed. You can override this default setting in any individual use of the shortcode by including the option content_style.

Shortcode Options

These are the parameters you can set in the shortcode:
categoryNo default. Required. Enter the slug of the category you'd like to use.
custom_fieldDefault is the option set above, if not empty. Otherwise, ignored.
titleDefault = h3. Can be any HTML tag name (b, i, u, h4, etc)
numberpostsDefault = 1. This is the number of posts that are called in.
classDefault = post. You can choose another class, for example, one controlled in your own theme's stylesheet, instead.
sideboxEmpty and ignored by default. If set to "true", puts the posts in a box floating at the right side of the page.
sideboxsizeEmpty and ignored by default. Only used if sidebox is set to true. Then, default = "small". Other options are: medium, large, xlarge.
content_styleDefault = option set above. To override the default, set to one of these other options in the shortcode: excerpt, title.
separatorDefault is a comma (,). Only used if content_style is set to title.
colsDefault = 1. Only other option is 2.
col_item_heightEmpty and ignored by default. Only used if cols is set to 2. Then the default = 260.
showthumbEmpty and ignored by default. If set to true, then the post thumbnail is displayed before the post. The image has the class attachment-thumbnail, so you can style it.
orderDefault is ASC. Can be set to DESC. Used only when a custom field is set.

 

'; } // On access of the admin page, register these variables (required for WP 2.7 & newer) function ahscp_init(){ if(function_exists('register_setting')){ register_setting('ahscp-options', 'ahscp_customfield'); register_setting('ahscp-options', 'ahscp_titletype'); register_setting('ahscp-options', 'ahscp_contentstyle'); } } // Only all the admin options if the user is an admin if(is_admin()){ add_action('admin_menu', 'ahscp_options'); add_action('admin_init', 'ahscp_init'); } // Set the default options when the plugin is activated function ahscp_activate(){ add_option('ahscp_customfield', ''); add_option('ahscp_titletype', ''); add_option('ahscp_contentstyle', ''); } register_activation_hook( __FILE__, 'ahscp_activate'); add_action('wp_head', 'ahscp_callposts_styles'); // so that widget text is analyzed for shortcodes add_filter('widget_text', 'do_shortcode'); ?>