Edit Settings. Version: 2.0.1 Author: April Hodge Silver Author URI: http://springthistle.com/ License: GPL2 Copyright 2011 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 */ $ahscpsett = array(); function ahscp_callposts_handler($atts) { $out = ''; global $post, $ahscpsett; 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, 'thumbsize'=>'medium', 'order'=>'DESC', 'dateformat'=>null, 'orderby'=>'post_date', 'continue_text'=>'Read more »', 'pre_continue_text'=>'', 'linktitle'=>'true', 'template'=>0, 'post_type'=>'post', 'heading'=>null, 'headingtag'=>'h3', ), $atts)); // for backwards compatibility if (empty($type)) $type = $category; if ($separator=='
  • ') $separator = 'list'; // 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($orderby)) $orderby = get_option('ahscp_orderby'); if (empty($content_style)) $content_style = get_option('ahscp_contentstyle'); if (!$dateformat) $dateformat = get_option('ahscp_dateformat'); if (empty($title)) $title = 'h3'; if (preg_match('/[0-9]*/',$thumbsize)) { $thumbsize = preg_split('/,/',$thumbsize); } // globalize options $ahscpsett['continue_text'] = $continue_text; $ahscpsett['pre_continue_text'] = $pre_continue_text; $ahscpsett['dateformat'] = $dateformat; $ahscpsett['title'] = $title; $ahscpsett['class'] = $class; $ahscpsett['content_style'] = $content_style; $ahscpsett['showthumb'] = $showthumb; $ahscpsett['thumbsize'] = $thumbsize; $ahscpsett['separator'] = $separator; $ahscpsett['linktitle'] = $linktitle; $ahscpsett['col_item_height'] = $col_item_height; $ahscpsett['template'] = $template; // if $category/$type has commas, turn it into a list of IDs $catids = ahscp_get_cats_array(); $category_ids = ""; if (!empty($type)) { if (preg_match('/,/',$type)) { $cnames = preg_split("/,[ ]*/",$type); $ahscpsett['single_cat_name'] = $cnames[0]; foreach ($cnames as $n) $category_ids .= $catids[$n].','; } else { $category_ids = $catids[$type]; $ahscpsett['single_cat_name'] = $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='.$custom_field.'&orderby=meta_value&order='.$order.'&post_type='.$post_type); $posts2 = get_posts('numberposts='.$numberposts.'&category='.$category_ids.'&orderby='.$orderby.'&order='.$order.'&post_type='.$post_type); if (!empty($custom_field)) { list($out1,$used_ids) = ahscp_spit_posts($posts1); list($out2,$discard) = ahscp_spit_posts($posts2,$used_ids); $out = $out1.$out2; } else { list($out,$discard) = ahscp_spit_posts($posts2); } // was anything even returned? if (strlen($out) > 0) { if (!$ahscpsett['template']) { if ($ahscpsett['content_style']=='title' && strstr('list',$ahscpsett['separator'])) { $out = ''; } if ($sidebox!=null) { $sizes = array('small'=>'210','medium'=>'300','large'=>'350','xlarge'=>'425'); $out = '
    '.$out.'
    '; } if ($cols > 1) { $style = ''; $out = $style.'
    '.$out.'
     
    '; } } else { if (get_option('ahscp_tmpl_'.$ahscpsett['template'].'_group')==1) $out = ''; } $finalstring = '
    '; if ($heading) $finalstring .= '<'.$headingtag.'>'.$heading.''; $finalstring .= $out; $finalstring .= '
    '; return $finalstring; } } /* * 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,$exclude=array()) { $used_ids = array(); $out = ''; global $more, $ahscpsett; $urlpath = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); foreach($posts as $post) : setup_postdata($post); $more = 0; if (!in_array($post->ID,$exclude)) { // Using a template? if ($ahscpsett['template']) { if (!empty($post->post_excerpt)) $excerpt = $post->post_excerpt; else $excerpt = ahscp_excerpt($post->post_content); $content = get_the_content($ahscpsett['continue_text']); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = preg_replace('/Read more »<\/a>/','Read more »',$content); if ($url = get_edit_post_link($post->ID)) $editlink = ' Edit'; $tmpl = stripslashes(get_option('ahscp_tmpl_'.$ahscpsett['template'].'_text')); $tmpl = preg_replace('/%%TITLE%%/',$post->post_title,$tmpl); $tmpl = preg_replace('/%%URL%%/',get_permalink($post->ID),$tmpl); $tmpl = preg_replace('/%%IMAGE%%/',get_the_post_thumbnail($post->ID, $ahscpsett['thumbsize']),$tmpl); $tmpl = preg_replace('/%%DATE%%/',get_the_time($ahscpsett['dateformat'],$post->ID),$tmpl); $tmpl = preg_replace('/%%CONTENT%%/',$content,$tmpl); $tmpl = preg_replace('/%%CONTENTNOIMG%%/',strip_tags($content,'