';
$out .= '<'.$settings['title'].'>';
if (!empty($settings['dateformat'])) $out .= get_the_time($settings['dateformat'],$post->ID).' - ';
// post title
if ($settings['linktitle']!='false') $out .= '
';
$out .= $post->post_title;
if ($settings['linktitle']!='false') $out .= '';
// edit link
if ($url = get_edit_post_link($post->ID)) $out .= '

';
$out .= ''.$settings['title'].'>';
if ($settings['showthumb']==true) {
$out .= get_the_post_thumbnail($post->ID, $settings['thumbsize']);
}
if ($settings['content_style']=='excerpt') {
if (!empty($post->post_excerpt)) $excerpt = $post->post_excerpt;
// else $excerpt = get_the_excerpt();
else $excerpt = ahscp_excerpt($post->post_content);
$out .= '
'.$excerpt.' '.$settings['pre_continue_text'].''.$settings['continue_text'].'
';
} else {
// default content_style=full
$content = get_the_content($settings['continue_text']);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = ereg_replace('
Read more »<\/a>','Read more »',$content);
if ($settings['showthumb']==true) $content = strip_tags($content,'
');
$out .= $content;
}
$out .= '
'; // end (or whatever)
} else {
if (strstr('list',$settings['separator'])) {
$out .= '
'.''.$post->post_title.''.''."\n";
} else {
$out .= '
'.$post->post_title.''.$settings['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:
[ahs_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');
}
/*
* ahscp_excerpt()
* returns a string that is an excerpt of the post content. replaces get_the_excerpt() which was causing problems
* @param string post_content
* @returns string excerpt
*/
function ahscp_excerpt($text) {
$text = strip_tags($text);
$text = preg_replace('/\[([^[])+\]/','',$text);
$text = preg_replace("/\n|\r/"," ",$text);
$text = ahscp_substrws($text,450);
return $text;
}
/* Thanks, Benny. http://www.php.net/manual/en/function.substr.php#90724 */
/**
* word-sensitive substring function with html tags awareness
* @param text The text to cut
* @param len The maximum length of the cut string
* @returns string
**/
function ahscp_substrws( $text, $len=180 ) {
if ( (strlen($text) > $len) ) {
$whitespaceposition = strpos($text," ",$len)-1;
if ($whitespaceposition > 0)
$text = substr($text, 0, ($whitespaceposition+1));
// close unclosed html tags
if (preg_match_all("|<([a-zA-Z]+)>|",$text,$aBuffer) ) {
if( !empty($aBuffer[1]) ) {
preg_match_all("|([a-zA-Z]+)>|",$text,$aBuffer2);
if( count($aBuffer[1]) != count($aBuffer2[1]) ) {
foreach( $aBuffer[1] as $index => $tag ) {
if( empty($aBuffer2[1][$index]) || $aBuffer2[1][$index] != $tag)
$text .= ''.$tag.'>';
}
}
}
}
}
return $text;
}
/**
* 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 settings apply to every instance of the shortcode on the site, old or new, unless the instance itself overrides this setting.
Shortcode Options
These are the parameters you can set in the shortcode:
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. |
orderby | Default = option set above. To override, use post_date or random in the shortcode. |
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. Any text you enter for this will be placed after each linked title. Special case: If you use <list>, the linked post titles will actually be enclosed in a UL and LIs. |
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's featured image is displayed before the post (You choose the featured image at the bottom right on the Edit Post page). The image has the class attachment-thumbnail, so you can style it. |
thumbsize | If you set showthumb to true, you can also set the size. The default is medium. Other options include thumbnail or large. If you provide two numbers separated by a comma, those two numbers will be used as the width and height. |
order | Default is ASC. Only other option is DESC. Used only when custom_field option is in use. |
continue_text | What text would you like people to see that they click on to read the rest of the post? This applies to both full and excerpt modes. Default is Read more ». Note: If you're using a theme that customizes the excerpt more link, this may interfere. You may want to set this to blank ("") |
pre_continue_text | If, when in excerpt mode, you'd like to prepend, say, an ellipsis (...) to your text before the continue_text, you can set it with this. |
linktitle | Default = true. If you don't want the post titles to be links (in excerpt or full mode), set this to false |
Shortcode Examples
prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE tt.taxonomy LIKE 'category' AND tt.term_id=t.term_id AND tt.term_id=1 ORDER BY t.slug";
$result = $wpdb->get_results($sql);
foreach ($result as $i) $slugexample = $i->slug;
?>
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"]
\n";
echo '";
echo "\n\n\n";
}
// 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');
register_setting('ahscp-options', 'ahscp_dateformat');
register_setting('ahscp-options', 'ahscp_orderby');
register_setting('ahscp-options', 'ahscp_css');
}
}
// 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', 'excerpt');
add_option('ahscp_dateformat', '');
add_option('ahscp_orderby', 0);
add_option('ahscp_css', ".callposts_2col .post { float: left; margin-right: 20px; border-bottom: 1px solid #999; overflow: hidden; clear: none; }\n.callposts_2col .post h3 { margin-bottom: 0; }\n.callposts_2col .clr { height: 20px; }\n.callposts.whitespace { background: #fff; width: 225px; float: right; margin-right: -10px; padding: 0 0 10px 10px; }\n.callposts .floatbox { background-color: #eee; padding: 15px; float: right; margin: 10px -10px 10px 10px;}\n.clr { clear: both; }");
}
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');
// activate post thumbnails
add_theme_support( 'post-thumbnails' );
//set_post_thumbnail_size(300, 300 );
?>