__('-- None --', ATOM),
'cover' => __('Cover', ATOM),
'uncover' => __('Uncover', ATOM),
'curtainX' => __('Curtain X', ATOM),
'curtainY' => __('Curtain Y', ATOM),
'fade' => __('Fade', ATOM),
'scrollUp' => __('Scroll Up', ATOM),
'scrollDown' => __('Scroll Down', ATOM),
'scrollLeft' => __('Scroll Left', ATOM),
'scrollRight' => __('Scroll Right', ATOM),
'scrollUp, scrollDown, scrollLeft, scrollRight' => __('Scroll Random', ATOM),
'shuffle' => __('Shuffle', ATOM),
'toss' => __('Toss', ATOM),
'wipe' => __('Wipe', ATOM))));
// easing equations used by effects
define("EASING", serialize(array(
'easeOutCirc' => __('Circular', ATOM),
'easeOutElastic' => __('Elastic', ATOM),
'easeOutBack' => __('Back', ATOM),
'easeOutBounce' => __('Bounce', ATOM),
'easeOutExpo' => __('Exponential', ATOM),
'easeOutQuad' => __('Quadratic', ATOM),
'easeOutQuart' => __('Quartic', ATOM),
'easeOutQuint' => __('Quintic', ATOM))));
// if the current wp version is lower than the minimum required version display a error message and don't go further
if (WP_VERSION < WP_REQ_VERSION):
add_action('admin_notices', 'atom_unsupported_wp_version');
add_action('wp', 'atom_unsupported_wp_version');
// if everything is ok, set up the theme
else:
require_once(TEMPLATEPATH.'/lib/widgets.php');
require_once(TEMPLATEPATH.'/lib/shortcodes.php');
if(is_admin()) require_once(TEMPLATEPATH.'/admin/interface.php');
// setup the theme
add_action('after_setup_theme', 'atom_setup');
// user functions
if(isset($_GET['atom_reset_user_functions'])) add_action('init', 'atom_user_functions');
// set up thumb sizes
add_action('init', 'atom_set_thumb_sizes', 99);
// ajax/get requests
add_action('template_redirect', 'atom_requests');
// setup widget areas
add_action('widgets_init', ATOM.'_widget_areas_init');
// remove theme settings on theme change?
if(atom_get_options('remove_settings')) add_action('switch_theme', 'atom_remove_options');
// include js and css
add_action('wp_head', 'atom_load_js', 1);
add_action('wp_head', 'atom_load_css', 1);
// advertisment blocks
add_action('wp', 'atom_setup_ads');
// footer hook
add_action('wp_footer', 'atom_footer', 99);
// compress html
if(atom_get_options('gzip'))
if (ob_get_length() === false && !ini_get("zlib.output_compression") && ini_get("output_handler") != "ob_gzhandler" && extension_loaded("zlib") && !headers_sent() && !is_admin() && stripos($_SERVER['REQUEST_URI'], 'wp-includes/js/tinymce') === false)
add_action('init', create_function('', '@ini_set("zlib.output_compression_level", 6); ob_start("ob_gzhandler");'));
// small page/menu "hacks"
add_filter('wp_nav_menu_args', 'atom_nav_menu_settings');
add_filter('page_css_class', 'atom_page_css_classes', 10, 2);
add_filter('nav_menu_css_class', 'atom_menu_css_classes', 10, 2);
return true;
endif;
return false;
}
/**
* Set up the theme and attach the core actions and filter hooks
*
* @since 1.0
*/
function atom_setup(){
// editor-style.css
add_editor_style();
// post thumbnails
add_theme_support('post-thumbnails');
// posts & comments RSS feed links
add_theme_support('automatic-feed-links');
// localize the theme
load_theme_textdomain(ATOM, TEMPLATEPATH.'/lang');
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/lang/$locale.php";
if (is_readable($locale_file)) require_once($locale_file);
// nav menus
register_nav_menus(
apply_filters('atom_nav_menus',
array('top' => __('Page Top', ATOM),
'primary' => __('Below Header', ATOM),
'footer' => __('Above Footer', ATOM))
));
// synchronize theme settings
atom_verify_options();
// content width
if (!isset($GLOBALS['content_width']) && atom_get_options('page_width') == 'fixed'):
$primary = explode(";", atom_get_options('dimensions_fixed_'.atom_get_options('layout')));
if(empty($primary[0])) $primary = 960; else $primary = intval($primary[0]);
$GLOBALS['content_width'] = ($primary - 20);
endif;
}
/**
* Set up post thumbnail sizes
*
* @since 1.0
*/
function atom_set_thumb_sizes(){
$size = atom_get_options('post_thumb_size');
if($size != 'media') $size = explode('x', atom_get_options('post_thumb_size'));
else $size = array(get_option('thumbnail_size_w'), get_option('thumbnail_size_h'));
set_post_thumbnail_size(intval($size[0]), intval($size[1]), true); // same as add_image_size('post-thumbnail' ...);
add_image_size('featured-thumbnail', 176, 176, true);
add_image_size('related-post-thumbnail', 100, 100, true);
// widgets may set additional sizes
do_action("atom_set_thumb_sizes");
}
/**
* Displays a error message telling the user that he needs to upgrade his Worpdress installation
*
* @since 1.0
*/
function atom_unsupported_wp_version(){
if(!is_admin()): ?>
Wordpress '.WP_REQ_VERSION.'');
else printf(__("The site is temporarily down for maintainance. Come back in a few minutes, or login in here if you're de site admin"), ' href="'.get_admin_url().'"');
if(current_user_can('edit_theme_options') && !is_admin()) echo ' '.__("Go to your Dashboard", ATOM).'';
?>
get_queried_object_id();
$hide = isset($instance['page-'.$post_id]) ? ($instance['page-'.$post_id]) : false;
}
if (!is_user_logged_in() && isset($instance['user-visitor']) && $instance['user-visitor']) $hide = true;
if (is_user_logged_in() && isset($instance['user-registered']) && $instance['user-registered']) $hide = true;
if ($hide) return false; else return $instance;
}
/**
* Get the status of a widgetized area (replaces wp's is_active_sidebar)
* This function also verifies if the widgets inside the sidebar are visible to the current user or not
* Note: If we're in preview mode areas are always considered to be active, but the returned widget count may be 0 (boolean false).
* (use type equivalence checking to avoid confusions)
*
* @since 1.0
*
* @global $wp_registered_widgets Stored registered widgets.
*
* @param string $index Area (sidebar) ID
* @return int|bool false or the visible widget count, based on widget visibility settings and current user status
*/
function atom_is_active_area($index){
global $wp_registered_widgets;
// always return true if the layout options are not enabled. obviously, the css designer wants to handle this
if(!atom_is_option_enabled('layout')) return true;
// -- same as atom_get_layout_type() --
// the layout theme setting has the lowest priority
$layout = atom_get_options('layout');
// custom page templates, higher priority
if(is_page_template('page-col-1.php')) $layout = 'col-1';
if(is_page_template('page-col-2-left.php')) $layout = 'col-2-left';
if(is_page_template('page-col-2-right.php')) $layout = 'col-2-right';
if(is_page_template('page-col-3.php')) $layout = 'col-3';
if(is_page_template('page-col-3-left.php')) $layout = 'col-3-left';
if(is_page_template('page-col-3-right.php')) $layout = 'col-3-right';
// override again if 'layout' custom field is present (highest priority)
if (is_single() || is_page()):
global $post;
$lcf = get_post_meta($post->ID, 'layout', true);
if($lcf) $layout = $lcf;
endif;
// -- /same as atom_get_layout_type() --
$index = (is_int($index)) ? "sidebar-$index" : sanitize_title($index);
$sidebars_widgets = wp_get_sidebars_widgets();
$visible_widgets = 0;
// only check widget settings if we have widgets in this sidebar
if(!empty($sidebars_widgets[$index]))
foreach($sidebars_widgets[$index] as $i => $w):
if(isset($wp_registered_widgets[$w])):
$number = $wp_registered_widgets[$w]['params'][0]['number'];
$s = get_option($wp_registered_widgets[$w]['callback'][0]->option_name);
$s = $s[$number];
if(atom_widget_visibility_check($s)) $visible_widgets++;
endif;
endforeach;
// always show active if we're in preview mode (eg. theme setting site preview), regardless of the contents
if(atom_preview_mode()) return $visible_widgets;
if(!empty($sidebars_widgets[$index]) && ($visible_widgets > 0)):
// check the current layout mode (for left/right sidebars) -- moved to atom_get_layout_type()
if($index == 'sidebar-1' || $index == 'sidebar-2'):
if($index == 'sidebar-1') return ($layout != 'col-1');
if($index == 'sidebar-2') return ($layout != 'col-1') && ($layout != 'col-2-left') && ($layout != 'col-2-right');
endif;
return $visible_widgets;
endif;
return false;
}
/**
* Check if we're in theme preview mode (Atom > Design)
*
* @since 1.0
*
* @return bool True or False
*/
function atom_preview_mode(){
if(isset($_GET['themepreview']) && current_user_can('edit_theme_options')) return true;
return false;
}
/**
* Get the current page URL
*
* @since 1.0
*
* @return string the page URL.
*/
function atom_get_current_page_url() {
$request = esc_url($_SERVER["REQUEST_URI"]);
// wp-themes fake request url fix :)
if (strpos($_SERVER["SERVER_NAME"], 'wp-themes.com') !== false) $request = str_replace($request, '/wordpress/', '/');
// ssl?
$pageURL = (is_ssl() ? 'https' : 'http').'://';
if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$request; else $pageURL .= $_SERVER["SERVER_NAME"].$request;
// check if the site uses "www" or not
if (false === strpos(get_option('home'), '://www.')) $pageURL = str_replace('://www.', '://', $pageURL);
if (false !== strpos(get_option('home'), '://www.') && false === strpos($pageURL, '://www.')) $pageURL = str_replace('://', '://www.', $pageURL);
return $pageURL;
}
/**
* Sort a multi-dimensional array by one of its subvalues
* from http://firsttube.com/read/sorting-a-multi-dimensional-array-with-php/
*
* @since 1.0
*
* @param array $a The Array
* @param string $subkey The Value
* @param string $order Sort order, ASC by defalt.
* @return array The sorted Array
*/
function atom_sort_array($a, $subkey, $order = 'ASC') {
foreach($a as $k => $v) $b[$k] = strtolower($v[$subkey]);
if($order != 'ASC') arsort($b); else asort($b);
foreach($b as $key => $val) $c[] = $a[$key];
return $c;
}
/**
* Output the favicon meta
*
* @since 1.0
*/
function atom_favicon(){
if($favicon = atom_get_options('favicon')) echo ''.PHP_EOL;
}
/**
* Load jQuery & related .js
*
* @since 1.0
* @todo append 'filemtime(url?action=jquery_init)' to script url to avoid cache?
*/
function atom_load_js(){
if(atom_get_options('jquery')):
// jquery
wp_enqueue_script('jquery');
// jquery plugins
wp_enqueue_script(ATOM, THEME_URL.'/c.php?file=js/jquery.atom.js', array('jquery'), $ver = THEME_VERSION, $in_footer = true);
if(atom_preview_mode())
wp_enqueue_script('post-message', THEME_URL.'/c.php?file=admin/pm.js', array('jquery'), $ver = THEME_VERSION, $in_footer = true);
// jquery init function
if(atom_get_options('jquery_init_query'))
wp_enqueue_script(ATOM.'-init', esc_url_raw(add_query_arg('atom_jquery', 1, (is_404() ? get_bloginfo('url') : atom_get_current_page_url()))), array('jquery', ATOM), $ver=THEME_VERSION, $in_footer=true);
endif;
}
/**
* Load styles
*
* @since 1.0
* @global $post object
*/
function atom_load_css(){
global $post;
// get the theme settings
$s = atom_get_options();
echo ''.PHP_EOL;
// print styles -- removed
//echo ''.PHP_EOL;
// color scheme stylesheet is loaded with link in preview mode, so we can replace it easily
if(atom_preview_mode() && !empty($style) && atom_is_option_enabled('color_scheme'))
echo ''.PHP_EOL;
}
/**
* wp_footer hook
*
* @since 1.0
*/
function atom_footer(){
if(!atom_get_options('jquery_init_query') && atom_get_options('jquery')): ?>
webmaster', ATOM), get_option('admin_email'));
else:
update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag.
wp_new_user_notification($user_id, $user_pass);
endif;
endif;
if($error):
echo json_encode(array('error' => $error));
else:
delete_transient($_POST['user-form']);
echo json_encode(array('success' => sprintf(__('A password was e-mailed to %s', ATOM), $user_email)));
endif;
else:
echo json_encode(array('error' => __('Provide a valid user name and e-mail address', ATOM)));
endif;
else:
echo json_encode(array('error' => __('Sorry, registration is disabled :(', ATOM)));
endif;
else:
$message = sprintf(__('Source IP Address: %s'), $_SERVER['REMOTE_ADDR']);
$country = atom_get_country($_SERVER['REMOTE_ADDR']);
if(isset($country['name'])) $message .= ' ('.$country['name'].')';
$message .= PHP_EOL.PHP_EOL;
$message .= __("Fields:", ATOM).PHP_EOL.PHP_EOL;
foreach($data['fields'] as $index)
if(isset($_POST[$index])) $message .= $index.': '.esc_attr($_POST[$index]).PHP_EOL;
wp_mail($data['target'], sprintf(__('Form submission from %s', ATOM), get_bloginfo('name')), $message);
delete_transient($_POST['user-form']);
echo json_encode(array('success' => __("Your message was sent succesfully", ATOM)));
endif;
else:
echo json_encode(array('error' => __("Failed. You appear to be a spam bot :)", ATOM)));
endif;
else:
echo json_encode(array('error' => __("Failed, hack attempt?", ATOM)));
endif;
exit();
endif;
// retrieve avatar (for comment form)
if(isset($_GET['atom_get_avatar'])):
if(isset($_GET['email'])) $email = strip_tags($_GET['email']); else $email = '';
if(isset($_GET['name'])) $name = strip_tags($_GET['name']); else $name = '';
if($email) echo atom_get_avatar($email, 48, false, $name);
exit();
endif;
// retrieve avatar (for comment form)
if(isset($_GET['atom_update_thumb'])):
$post_id = intval($_GET['post_id']);
$thumb_id = intval($_GET['thumb_id']);
$size = esc_attr($_GET['attachment_size']);
atom_update_post_thumb($thumb_id, $size);
echo atom_get_post_thumb($post_id, $size);
exit();
endif;
// jquery initialization
if(isset($_GET['atom_jquery'])):
include_once(TEMPLATEPATH . '/js/jquery.init.php');
exit();
endif;
// print preview
if(isset($_GET['atom_print'])):
atom_print_preview();
exit();
endif;
// print preview
if(isset($_GET['atom_reset_user_functions'])):
if(current_user_can('edit_themes')):
_e("User functions have been reset. Make sure your PHP code is correct next time :) ", ATOM);
echo '
'.esc_attr(atom_get_options('functions')).'
';
_e("(old user functions)", ATOM);
atom_update_options('ID, 'redirect', true)) wp_redirect(esc_url($url), 301); // @todo: add redirect type cf.
endif;
}
/**
* Return the default theme settings
*
* @since 1.0
*
* @return array The theme settings
*/
function atom_default_settings(){
$defaults = call_user_func(ATOM.'_active_settings');
// check for new default setting entries from other sources (plugins, child themes etc)
$defaults = apply_filters("atom_default_settings", $defaults);
return $defaults;
}
/**
* Set up advertisment blocks
*
* @since 1.0
*/
function atom_setup_ads(){
function atom_ad_posts(){
global $wp_query;
if(!$ad = atom_get_options('ad_posts_code')) return;
$show = (atom_get_options('ad_posts_home_only') && (is_front_page()) || (!atom_get_options('ad_posts_home_only')));
if (is_user_logged_in() && atom_get_options('ad_visitors_only')) $show = false;
$slot = atom_get_options('ad_posts_count');
if(($wp_query->current_post) + 1 == intval($slot)) echo $ad;
}
function atom_ad_before_content(){
if(!$ad = atom_get_options('ad_before_content_code')) return;
$show = (atom_get_options('ad_before_content_home_only') && (is_front_page()) || (!atom_get_options('ad_before_content_home_only')));
if (is_user_logged_in() && atom_get_options('ad_visitors_only')) $show = false;
if($show) echo $ad;
}
function atom_ad_comments(){
global $__comment_count;
$show = ($__comment_count == atom_get_options('ad_comments_count')) && ($ad = atom_get_options('ad_comments_code'));
if (is_user_logged_in() && atom_get_options('ad_visitors_only')) $show = false;
if (atom_get_options('ad_comments_open_only') && !comments_open()) $show = false;
if($show) echo '
'.$ad.'
';
}
add_action('atom_before_main_content','atom_ad_before_content');
add_action('atom_after_post', 'atom_ad_posts');
add_action('atom_before_comment', 'atom_ad_comments');
}
/**
* Set up the theme settings
* This should only run once (after the theme is activated for the 1st time)
*
* @since 1.0
*/
function atom_setup_options() {
// remove old settings
atom_remove_options();
// update the db with the default settings
atom_update_options(atom_default_settings());
// add our link in the blogroll if it doesn't exist -- only runs on 1st theme install -- or not :)
// $found = false;
// $links = get_bookmarks(array('hide_invisible' => 0));
// foreach ($links as $link)
// if($link->link_url == 'http://digitalnature.ro/') $found = true;
//
// if(!$found)
// wp_insert_link(array(
// 'link_name' => 'Digital Nature',
// 'link_url' => 'http://digitalnature.ro/',
// 'link_rss' => 'http://digitalnature.ro/feed/'
// ));
//
// no active widgets?
// add a few then, since a lot of people don't know about widgets other than default ones.
// this way they may find out about them by trying to remove the ones below :)
if(atom_is_active_area('sidebar-1') === false):
// 3 arbitrary post widgets (to use with tabs)
update_option('widget_atom_posts', array(
2 => array('title' => __('Recent', ATOM),
'post_type' => 'post',
'mode' => 'full',
'order_by' => 'date',
'category' => 0,
'number' => 4,
'word_count' => 20,
'thumb_size' => 48,
'more' => true),
3 => array('title' => __('Popular', ATOM),
'post_type' => 'post',
'mode' => 'full',
'order_by' => 'comment_count',
'category' => 0,
'number' => 4,
'word_count' => 20,
'thumb_size' => 48,
'more' => true),
4 => array('title' => __('Random', ATOM),
'post_type' => 'post',
'mode' => 'full',
'order_by' => 'rand',
'category' => 0,
'number' => 4,
'word_count' => 20,
'thumb_size' => 48,
'more' => true),
'_multiwidget' => 1));
$widgets_a = array('atom_posts-2', 'atom_posts-3', 'atom_posts-4');
$tabs = array();
foreach($widgets_a as $widget) $tabs[] = substr(md5($widget), 0, 8);
// search
update_option('widget_search', array(2 => array(
'title' => ''),
'_multiwidget' => 1));
// tabs
update_option('widget_atom_tabs', array(2 => array(
'widgets' => $tabs,
'effect' => 'fade',
'easing' => 'easeOutExpo'),
'_multiwidget' => 1));
// login
update_option('widget_atom_login', array(2 => array(
'title' =>__('Log in', ATOM),
'text' => __("Hello Guest. Login below if you have a account", ATOM),
'dashboard' => 1,
'profile' => 1,
'write' => 1,
'comments' => 0),
'_multiwidget' => 1));
// authors (we add it only if the blog has more than 7 authors)
if(count(explode(',', wp_list_authors(array('echo' => 0, 'style' => 'none', 'html' => 0)))) > 7):
update_option('widget_atom_authors', array(2 => array(
'title' => __("Authors", ATOM),
'mode' => 'full',
'avatar_size' => 48,
'sort_by' => 'post_count',
'hide_empty' => true,
'exclude_admin' => false),
'_multiwidget' => 1));
// otherwise add a blogroll
else:
update_option('widget_atom_links', array(2 => array(
'title' => __("Blogroll", ATOM),
'category' => '',
'order_by' => 'name',
'hide_invisible' => true,
'image' => false,
'rating' => true,
'description' => true,
'limit' => 24),
'_multiwidget' => 1));
endif;
// twitter
update_option('widget_atom_twitter', array(2 => array(
'title' => __('My latest tweets', ATOM),
'user' => 'tweetnorris',
'count' => 4,
'info' => true,
'cache' => 90),
'_multiwidget' => 1));
$widgets_s1 = array('search-2', 'atom_tabs-2', 'atom_login-2', 'atom_authors-2', 'atom_links-2', 'atom_twitter-2');
// update sidebars
update_option('sidebars_widgets', array('sidebar-1' => $widgets_s1, 'arbitrary' => $widgets_a, 'wp_inactive_widgets' => array(),
));
endif;
// action hook, probably useless
do_action('atom_setup_options');
}
/**
* Synchronize theme settings (eg. after updating)
*
* @since 1.0
*/
function atom_verify_options(){
$default_settings = atom_default_settings();
$current_settings = atom_get_options();
// if settings are not present (new theme install), load the defaults
if(!$current_settings):
atom_setup_options();
add_action('admin_notices', 'atom_theme_install_notification');
else:
// only go further if the theme version from the database differs from the one in the theme files
if (version_compare($current_settings['theme_version'], THEME_VERSION, '!=')):
// check for new settings and load defaults
foreach($default_settings as $option => $value)
if(!array_key_exists($option, $current_settings)) $current_settings[$option] = $default_settings[$option];
// update theme version
$current_settings['theme_version'] = THEME_VERSION;
atom_update_options($current_settings);
do_action('atom_verify_options');
endif;
endif;
}
/**
* First theme install notification message
*
* @since 1.0
*/
function atom_theme_install_notification(){ ?>
theme settings page.', ATOM), THEME_FULL_NAME, 'a href="'.get_admin_url('theme-settings').'"'); ?>
ID, 'layout', true);
if($lcf) $layout = $lcf;
endif;
if(!atom_preview_mode()):
$s1_active = atom_is_active_area('sidebar-1');
$s2_active = atom_is_active_area('sidebar-2');
// revert to a different layout if the current area is empty (or no widgets are visible)
if(!$s1_active && ($layout != 'col-1')) $layout = 'col-1';
if(!$s2_active && ($layout == 'col-3' || $layout == 'col-3-left' || $layout == 'col-3-right'))
if($s1_active) $layout = 'col-2-right'; else $layout = 'col-1';
endif;
return $layout;
}
/**
* Formats and outputs the current page document title
*
* @since 1.0
* @global $wp_query object
*
* @param string $separator Optional. Title separator. eg. " | ", " - " etc...
*/
function atom_document_title($separator = " « "){
global $wp_query;
$doctitle = get_bloginfo('name');
$desc = get_bloginfo('description');
if (is_front_page() && is_home() && !empty($desc)):
$doctitle .= $separator.$desc;
elseif (is_home() || is_singular()):
$id = $wp_query->get_queried_object_id();
if($meta = get_post_meta($id, 'title', true)) $doctitle .= $separator.$meta;
$doctitle .= (empty($meta) && is_front_page() && !empty($desc)) ? $separator.$desc : $separator.get_post_field('post_title', $id);
elseif (is_archive()):
if (is_category() || is_tag() || is_tax()):
$term = $wp_query->get_queried_object();
$doctitle .= $separator.$term->name;
elseif (is_author()):
$doctitle .= $separator.get_the_author_meta('display_name', get_query_var('author'));
elseif (is_date()):
if (is_day())
$doctitle .= $separator.sprintf(__('Archive for %s', ATOM), get_the_time(apply_filters('doc_title_archive_day_format', 'F jS, Y')));
elseif (get_query_var('w'))
$doctitle .= $separator.$separator.sprintf(__('Archive for week %1$s of %2$s', ATOM), get_the_time('W'), get_the_time('Y'));
elseif (is_month())
$doctitle .= $separator.sprintf(__('Archive for %s', ATOM), single_month_title(' ', false));
elseif (is_year())
$doctitle .= $separator.sprintf(__('Archive for year %s', ATOM), get_the_time('Y'));
endif;
elseif (is_search()):
$doctitle .= $separator.sprintf(__('Search results for %s', ATOM),'"'.esc_attr(get_search_query()).'"');
elseif (is_404()):
$doctitle .= $separator.__('404 Not Found', ATOM);
endif;
/* If paged. */
if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1 && !is_404())
$doctitle .= $separator.sprintf(__('Page %s', ATOM), $page);
/* if comment page... */
if (get_query_var('cpage'))
$doctitle .= $separator.sprintf(__('Comment Page %s', ATOM), get_query_var('cpage'));
/* Apply the wp_title filters so we're compatible with plugins. */
$doctitle = apply_filters('wp_title', $doctitle, $separator, '');
echo $doctitle;
}
/**
* Generates and outputs the current page meta description field
*
* @since 1.0
* @global $wp_query object
*/
function atom_meta_description() {
if(!atom_get_options('meta_description')) return false;
global $wp_query;
// blog description on the homepage
if (is_home()): $description = get_bloginfo('description');
// single pages?
elseif (is_singular()):
// custom field, if present
$description = get_metadata('post', $wp_query->post->ID, 'description', true);
// if not, and we're on a static homepage use the blog description
if (empty($description) && is_front_page()):
$description = get_bloginfo('description');
// otherwise use the post excerpt
elseif (empty($description)):
$description = get_post_field('post_excerpt', $wp_query->post->ID);
endif;
// archive pages?
elseif (is_archive()):
// author bio on author pages
if (is_author()):
$description = get_the_author_meta('description', get_query_var('author'));
// taxonomy term description on category/tags/etc...
elseif (is_category() || is_tag() || is_tax()):
$description = term_description('', get_query_var('taxonomy'));
endif;
endif;
if (!empty($description)):
// remove html formatting
$description = str_replace(array("\r", "\n", "\t"),'',esc_attr(strip_tags($description)));
// output (and allow user to change the content trough a filter hook)
echo ''.PHP_EOL;
endif;
}
/**
* Output the site logo HTML
*
* @since 1.0
*
* @param string $image_path Image URL
* @param string $image_size Optional. Image size (WxH)
*/
function atom_logo($image_path = '', $image_size = ''){
do_action('atom_before_logo');
if(!$image_path):
$image_path = atom_get_options('logo');
// if(!$image_size): $image_size = atom_get_options('logo_size'); endif; @todo auto image-size
endif;
if($image_size) $image_size = 'width="'.substr($image_size, 0, strpos($image_size, "x")).'" height="'.substr($image_size, strpos($image_size, 'x')+1).'"';
$sitename = apply_filters('atom_logo_title', get_bloginfo('name'));
$siteurl = apply_filters('atom_logo_url', get_bloginfo('url'));
$image_path = apply_filters('atom_logo_image', $image_path);
// h1 only on the front/home page, for seo reasons
$tag = (is_home() || is_front_page()) ? 'h1' : 'div';
$output = '<'.$tag.' id="logo">';
if($image_path): // logo image?
$output .= '';
else:
$words = explode(" ", $sitename); // we get a special treat if the logo is made out of 2 or 3 words
if(!empty($words[1]) && empty($words[3])):
$words[1] = ''.$words[1].'';
$sitename = implode(" ", $words); // leave the space here and remove it trough css to avoid seo problems
endif;
$output .= ''.apply_filters('atom_logo_title_html', $sitename).'';
endif;
$output .= ''.$tag.'>';
echo apply_filters('atom_logo', $output);
do_action('atom_after_logo');
}
/**
* Generates semantic classes for BODY element (mostly based on the sandbox theme)
*
* @since 1.0
* @global $wp_query object
* @global $current_user object
*
* @param string $class Optional. Extra classes to add
*/
function atom_body_class($class = ''){
global $wp_query, $current_user, $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
$s = atom_get_options();
// Generic semantic classes for what type of content is displayed
is_front_page() ? $classes[] = 'home' : null; // For the front page, if set
is_home() ? $classes[] = 'blog' : null; // For the blog posts page, if set
is_archive() ? $classes[] = 'archive' : null;
is_date() ? $classes[] = 'date' : null;
is_search() ? $classes[] = 'search' : null;
is_attachment() ? $classes[] = 'attachment' : null;
is_404() ? $classes[] = 'not-found' : null; // CSS does not allow a digit as first character
// Special classes for BODY element when a single post
if (is_single()):
$postname = $wp_query->post->post_name;
the_post();
// Adds 'single' class and class with the post ID
$classes[] = 'single-post title-' . $postname;
// Adds category classes for each category on single posts
if ($cats = get_the_category()) foreach ($cats as $cat) $classes[] = 'category-'.$cat->slug;
// Adds tag classes for each tags on single posts
if ($tags = get_the_tags()) foreach ($tags as $tag) $classes[] = 'tag-'.$tag->slug;
// Adds author class for the post author
$classes[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta('user_login')));
rewind_posts();
elseif (is_author()): // Author name classes for BODY on author archives
$author = $wp_query->get_queried_object();
$classes[] = 'author';
$classes[] = 'author-' . $author->user_nicename;
elseif (is_category()): // Category name classes for BODY on category archvies
$cat = $wp_query->get_queried_object();
$classes[] = 'category';
$classes[] = 'category-' . $cat->slug;
elseif (is_tag()): // Tag name classes for BODY on tag archives
$tags = $wp_query->get_queried_object();
$classes[] = 'tag';
$classes[] = 'tag-' . $tags->slug;
elseif (is_page()): // Page author for BODY on 'pages'
$pagename = $wp_query->post->post_name;
$pageID = $wp_query->post->ID;
$page_children = wp_list_pages("child_of=$pageID&echo=0");
the_post();
$classes[] = 'single-page page-' . $pagename;
$classes[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta('user_login')));
// Checks to see if the page has children and/or is a child page; props to Adam
if ($page_children) $classes[] = 'level-parent';
if ($wp_query->post->post_parent) $classes[] = 'level-child';
rewind_posts();
elseif (is_search()): // Search classes for results or no results
the_post();
if (have_posts()) $classes[] = 'search-results'; else $classes[] = 'search-no-results';
rewind_posts();
endif;
// generate layout class
$classes[] = atom_get_layout_type();
// fixed/fluid page
$classes[] = $s['page_width'];
// font style -- removed
//$classes[] = 'font-'.$s['font_style'];
// For when a visitor is logged in while browsing
if ($current_user->ID) $classes[] = 'loggedin';
// detect browser
if($is_lynx) $browser = 'lynx';
elseif($is_gecko) $browser = 'gecko';
elseif($is_opera) $browser = 'opera';
elseif($is_NS4) $browser = 'ns4';
elseif($is_safari) $browser = 'safari';
elseif($is_chrome) $browser = 'chrome';
elseif($is_IE) $browser = 'ie';
else $browser = 'unknown';
if($is_iphone) $browser .= '-iphone';
$classes[] = 'browser-'.$browser;
// user classes
if (!empty($class)):
if (!is_array($class)) $class = preg_split('#\s+#', $class);
$classes = array_merge($classes, $class);
endif;
$class = join(' ', apply_filters('body_class', $classes));
echo $class;
}
/**
* Generates semantic classes for posts
*
* @since 1.0
* @global $post object
*
* @param string $class Optional. Extra classes to output
*/
function atom_post_class($class = '', $return = false){
global $post;
static $post_alt;
// add hentry for microformats compliance and the post type
$classes = array('hentry', $post->post_type);
// post alt
$classes[] = 'post-' . ++$post_alt;
$classes[] = ($post_alt % 2) ? 'odd' : 'even alt';
// clear-block class, omitted in thumbnail-only mode
if(atom_thumbnails_only() && !atom_is_sticky()) $classes[] = 'thumb-only'; else $classes[] = 'clear-block';
// asides?
if(atom_is_asides()) $classes[] = 'asides';
// thumbnail classes
if(atom_get_options('post_thumbs') && !atom_is_sticky() && !atom_is_asides() && !is_singular()) $classes[] = 'thumb-'.atom_get_options('post_thumbs_mode');
// author
$classes[] = 'author-'.sanitize_html_class(get_the_author_meta('user_nicename'), get_the_author_meta('ID'));
// sticky? (only on home/blog page)
if (atom_is_sticky()) $classes[] = 'sticky';
// password-protected?
if (post_password_required()) $classes[] = 'protected';
// post category & tags */
// @todo add other tax entries
if ('post' == $post->post_type)
foreach (array('category', 'post_tag') as $tax)
foreach ((array)get_the_terms($post->ID, $tax) as $term)
if (!empty($term->slug)) $classes[] = $tax . '-' . sanitize_html_class($term->slug, $term->term_id);
// user classes
if (!empty($class)):
if (!is_array($class)) $class = preg_split('#\s+#', $class);
$classes = array_merge($classes, $class);
endif;
// join all and output them
$class = join(' ', $classes);
if($return) return apply_filters("post_class", $class); else echo apply_filters("post_class", $class);
}
/**
* Generates semantic classes for comments
*
* @since 1.0
* @global $post object
* @global $comment object
*
* @param string $class Optional. Extra classes to output
*/
function atom_comment_class($class = '') {
global $post, $comment;
$classes = get_comment_class();
// avatars enabled?
if (get_option('show_avatars')) $classes[] = 'with-avatars';
// user roles
if ($comment->user_id > 0):
$user = new WP_User($comment->user_id);
if (is_array($user->roles))
foreach ($user->roles as $role) $classes[] = "role-{$role}";
$classes[] = 'user-'.sanitize_html_class($user->user_nicename, $user->ID);
else:
$classes[] = 'reader name-'.sanitize_title(get_comment_author());
endif;
// user classes
if (!empty($class)):
if (!is_array($class)) $class = preg_split('#\s+#', $class);
$classes = array_merge($classes, $class);
endif;
echo join(' ', apply_filters("comment_class", $classes));
}
/**
* Gets the country info based on a IP address
*
* @since 1.0
*
* @param string $ip User IP Address
* @return array Country Name and Country Code
*
* @todo update the ip2c database
*/
function atom_get_country($ip) {
require_once(TEMPLATEPATH.'/ip2c/ip2c.php');
if (isset($GLOBALS['ip2c'])):
global $ip2c;
else:
$ip2c = new ip2country(TEMPLATEPATH.'/ip2c/ip-to-country.bin');
$GLOBALS['ip2c'] = $ip2c;
endif;
$country = $ip2c->get_country($ip);
if ($country):
$code = strtolower($country['id2']);
$name = ucwords(strtolower($country['name']));
return array('code' => $code, 'name' => $name);
else:
return false;
endif;
}
/**
* Generates page navigation links
* based on WP-Pagenavi - http://wordpress.org/extend/plugins/wp-pagenavi
*
* @since 1.0
* @global $wp_query object
*
* @param string $class Extra classes to output
* @param bool $pages Show numbered page navigation
* @param int $pages_to_show Numbered page links to show
* @param bool $extended If true, adds 3 extra page links for every 10nth page
* @param bool $status Show status text (eg. page X out of Y)
*/
function atom_pagenavi($class = '', $pages = true, $pages_to_show = 5, $extended = false, $status = false){
// don't show on single pages
if (is_single()) return false;
global $wp_query;
$posts_per_page = intval(get_query_var('posts_per_page'));
$paged = intval(get_query_var('paged'));
$request = $wp_query->request;
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
if ($max_page <= 1) return false; // dont show if we only have one page
if (empty($paged)) $paged = 1;
$larger_page_to_show = 3;
$larger_page_multiple = 10;
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor($pages_to_show_minus_1/2);
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged - $half_page_start;
if ($start_page <= 0) $start_page = 1;
$end_page = $paged + $half_page_end;
if (($end_page - $start_page) != $pages_to_show_minus_1) $end_page = $start_page + $pages_to_show_minus_1;
if ($end_page > $max_page):
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
endif;
if ($start_page <= 0) $start_page = 1;
$out = '';
if($status) $out .= ''.sprintf(__('Page %1$s of %2$s', ATOM), $paged, $max_page).'';
// add classes to prev/next so they can be styled
add_filter('previous_posts_link_attributes', create_function('', 'return \'class="previous"\'; '));
add_filter('next_posts_link_attributes', create_function('', 'return \'class="next"\'; '));
$out .= get_previous_posts_link(__('« Previous', ATOM));
// numbered page links
if($pages):
if ($start_page >= 2 && $pages_to_show < $max_page):
$out .= '1';
$out .= '...';
endif;
$larger_pages_array = array();
if ($larger_page_multiple)
for ($i = $larger_page_multiple; $i <= $max_page; $i += $larger_page_multiple) $larger_pages_array[] = $i;
if($extended):
$larger_page_start = 0;
foreach ($larger_pages_array as $larger_page)
if ($larger_page < $start_page && $larger_page_start < $larger_page_to_show):
$out .= ''.$larger_page.'';
$larger_page_start++;
endif;
endif;
for ($i = $start_page; $i <= $end_page; $i++)
if ($i == $paged) $out .= ''.$i.'';
else $out .= ''.$i.'';
if($extended):
$larger_page_end = 0;
foreach ($larger_pages_array as $larger_page)
if ($larger_page > $end_page && $larger_page_end < $larger_page_to_show):
$out .= ''.$larger_page.'';
$larger_page_end++;
endif;
endif;
if ($end_page < $max_page):
$out .= '...';
$out .= ''.$max_page.'';
endif;
endif;
$out .= get_next_posts_link(__('Next »', ATOM), $max_page);
?>
60 * 60 * 24 * 365, // 31,536,000 seconds
'month' => 60 * 60 * 24 * 30, // 2,592,000 seconds
'week' => 60 * 60 * 24 * 7, // 604,800 seconds
'day' => 60 * 60 * 24, // 86,400 seconds
'hour' => 60 * 60, // 3600 seconds
'minute' => 60, // 60 seconds
'second' => 1 // 1 second
);
$newer_date = ($newer_date == false) ? (time()+(60*60*get_option("gmt_offset"))) : $newer_date;
$since = $newer_date - $older_date;
foreach ($chunks as $key => $seconds)
if (($count = floor($since / $seconds)) != 0) break;
$messages = array(
'year' => _n('%s year ago', '%s years ago', $count, ATOM),
'month' => _n('%s month ago', '%s months ago', $count, ATOM),
'week' => _n('%s week ago', '%s weeks ago', $count, ATOM),
'day' => _n('%s day ago', '%s days ago', $count, ATOM),
'hour' => _n('%s hour ago', '%s hours ago', $count, ATOM),
'minute' => _n('%s minute ago', '%s minutes ago', $count, ATOM),
'second' => _n('%s second ago', '%s seconds ago', $count, ATOM),
);
return sprintf($messages[$key],$count);
}
/**
* Removes HTML tags from a string, including the content between them
* from http://www.php.net/manual/en/function.strip-tags.php#86964
*
* @since 1.0
*
* @param string $text What to filter
* @param string $tags Allowed tags.
* @param bool $invert Remove the $tags above, allow others ($tags becomes Disallowed tags)
* @return string Filtered content
*/
function atom_strip_tags_content($text, $tags = '', $invert = false) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0){
if($invert == false)
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?\1>@si', '', $text);
else
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?\1>@si', '', $text);
}
elseif($invert == false) {
return preg_replace('@<(\w+)\b.*?>.*?\1>@si', '', $text);
}
return $text;
}
/**
* Filters content based on specific parameters, and appends a "read more" link if needed.
*
* @since 1.0
*
* @param string $the_contents What to filter
* @param string $read_more_tag Optional. Read more text (default is "read more")
* @param string $permalink_to Optional. Read more target link (default is the post permalink)
* @param int $max_words Optional. Maximum number of words (default is 100)
* @param array $allowed_tags Optional. HTML tags to keep
* @param bool $strip_content Optional. Strip content between tags (false by default)
* @return string Filtered content
*/
function atom_filter_content($content, $read_more_tag = '', $permalink_to = false, $max_words = 100, $allowed_tags = array('a', 'div', 'abbr', 'blockquote', 'b', 'cite', 'pre', 'code', 'em', 'label', 'small', 'i', 'p', 'span', 'strong', 'ul', 'ol', 'li', 'dl', 'dt', 'dd'), $strip_content = true, $balance_spacing = false){
if($content != ''):
// replace whitespace characters with a single space char
if($balance_spacing) $content = str_replace(array("\n", "\r", "\t", " ", "\o", "\xOB"), ' ', $content);
$content = str_replace(']]>', ']]>', $content);
// some filter hooks
$read_more_class = apply_filters('read_more_class', 'more-link');
$allowed_tags = apply_filters('atom_filter_content_allowed_tags', $allowed_tags);
$allowed_tags = '<' .implode('><', $allowed_tags).'>';
if($strip_content) $content = atom_strip_tags_content($content, $allowed_tags);
// required even if strip_content is true
$content = strip_tags($content, $allowed_tags);
// exclude HTML and shortcodes from counting words
$content = strip_shortcodes($content);
if(!is_numeric($max_words)) $max_words = 9999; // assuming full post
// count all
if($max_words > count(preg_split('/[\s]+/', strip_tags($content), -1))) return $content;
$all_chunks = preg_split('/([\s]+)/', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$content = '';
$count_words = 0;
$enclosed_by_tag = false;
foreach($all_chunks as $chunk):
// is tag opened?
if(0 < preg_match('/<[^>]*$/s', $chunk)) $enclosed_by_tag = true; elseif(0 < preg_match('/>[^<]*$/s', $chunk)) $enclosed_by_tag = false;
// get entire word
if(!$enclosed_by_tag && '' != trim($chunk) && substr($chunk, -1, 1) != '>') $count_words ++;
$content .= $chunk;
if($count_words >= $max_words && !$enclosed_by_tag) break;
endforeach;
// looks better before force_balance_tags(), but may produce invalid html
if($permalink_to)
$content = $content.' '.($read_more_tag !== TRUE ? $read_more_tag : __('More...', ATOM)).'';
else $content = $content.' [...]';
// native WordPress check for unclosed tags
$content = force_balance_tags($content);
endif;
return $content;
}
/**
* Get the user avatar based on his email address
*
* @since 1.0
*
* @param string $email Valid Email Address
* @param int $size Optional. Image size
* @param string $default Default image
* @param string $alt Alternate text
* @return string Avatar image (HTML)
*/
function atom_get_avatar($email, $size = 48, $default = '', $alt = false){
// if today is April 1st show a pony :)
if(date('m-d') == '04-01') return '';
// if not, display the user's gravatar
else return get_avatar($email, $size, $default, $alt);
}
/**
* Get the first image from a post
*
* @since 1.0
* @global $post object
*
* @param object $source post object
* @return string Image (HTML)
*/
function atom_get_first_post_image($source = false) {
global $post;
if (!$source) $source = $post;
$first_img = '';
$output = preg_match_all('//i', $source->post_content, $matches);
$first_img = $matches [1][0];
return $first_img;
}
/**
* Output the post thumbnail
* Replaces get_the_post_thumbnail()
*
* @since 1.0
* @global $id int Current Post ID
* @global $_wp_additional_image_sizes array Image sizes
*
* @param int $post_id Optional. Post ID
* @param string $size Optional. Thumbnail size
* @return string Thumbnail image
*/
function atom_get_post_thumb($post_id = NULL, $size = 'post-thumbnail', $attr = ''){
global $id, $_wp_additional_image_sizes;
$post_id = (NULL === $post_id) ? $id : $post_id;
$html = '';
$width = $_wp_additional_image_sizes[$size]['width'];
$height = $_wp_additional_image_sizes[$size]['height'];
$t = get_post_meta($post_id, '_thumbnail_id', true);
if(!$t && atom_get_options('post_thumb_auto')):
$attachments = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
$attachment = array_shift($attachments);
$t = ($attachment ? $attachment->ID : false);
endif;
if($t):
$meta = wp_get_attachment_metadata($t);
// @todo: check this -- some weird notices here
if(!is_array($meta)) return;
$small_image = (!isset($meta['sizes'][$size]) && ($meta['width'] < $width) && ($meta['height'] < $height));
if(isset($meta['sizes'][$size]['width']) && isset($meta['sizes'][$size]['height']))
$processed = ($meta['sizes'][$size]['width'] == $width) || ($meta['sizes'][$size]['height'] == $height);
else $processed = false;
if(!$small_image && !$processed):
$html = '';
else:
do_action('begin_fetch_post_thumbnail_html', $post_id, $t, $size);
$html = wp_get_attachment_image($t, $size, false, $attr);
do_action('end_fetch_post_thumbnail_html', $post_id, $t, $size);
endif;
endif;
if(!$html) $html = '';
return apply_filters('post_thumbnail_html', $html, $post_id, $t, $size, $attr);
}
/**
* Update the post thumbnails (generate new image size)
* Should be called trough ajax because it requires a lot of cpu and it will slow down page loading
*
* @since 1.0
* @global $_wp_additional_image_sizes array Image sizes
*
* @param int $t Thumbnail (attachment) ID
* @param string $size Optional. Thumbnail size
* @return bool true if the new image size was generated, false otherwise
*/
function atom_update_post_thumb($t = false, $size = 'post-thumbnail'){
if($t && atom_get_options('generate_thumbs')):
global $_wp_additional_image_sizes;
$width = $_wp_additional_image_sizes[$size]['width'];
$height = $_wp_additional_image_sizes[$size]['height'];
$meta = wp_get_attachment_metadata($t);
$small_image = (!isset($meta['sizes'][$size]) && ($meta['width'] < $width) && ($meta['height'] < $height));
if(isset($meta['sizes'][$size]['width']) && isset($meta['sizes'][$size]['height']))
$processed = ($meta['sizes'][$size]['width'] == $width) || ($meta['sizes'][$size]['height'] == $height);
else $processed = false;
// make sure the desired size doesn't exist
if(!$small_image && !$processed):
// based on the 'regenerate thumbnails' plugin
$full_size_path = get_attached_file($t);
if($full_size_path):
require_once(ABSPATH.'/wp-admin/includes/image.php');
wp_update_attachment_metadata($t, wp_generate_attachment_metadata($t, $full_size_path));
return true;
endif;
endif;
endif;
return false;
}
/**
* Retrieve the terms for a post.
* uses wp_get_post_terms()
*
* @since 1.0
* @global $id int Current Post ID
*
* @param int $post_id Post ID (Optional inside the loop, required outside the loop)
* @param string $taxonomy Term Taxonomy (optional, defaults to tags)
* @return array|bool Links, or false if no terms found
*/
function atom_get_post_terms($post_id = NULL, $taxonomy = 'post_tag'){
global $id;
$post_id = (NULL === $post_id) ? $id : $post_id;
$terms = wp_get_post_terms($post_id, $taxonomy);
if ($terms):
$output = array();
foreach($terms as $term)
$output[] .= ''.apply_filters('atom_term_name', $term->name).'';
return $output;
endif;
return false;
}
/**
* Check if a post is marked as "asides"
*
* @since 1.0
* @global $id int Current Post ID
*
* @param int $post_id Post ID (Optional inside the loop, required outside the loop)
* @return bool True or false
*/
function atom_is_asides($post_id = NULL){
if(!atom_is_option_enabled('asides') || is_singular()) return false;
global $id;
$post_id = (NULL === $post_id) ? $id : $post_id;
return (get_post_meta($post_id, 'asides', true) || in_category(atom_get_options('asides')));
}
/**
* Check if a post is marked as "sticky"
* same as is_sticky(), but also checks if the post is on the home page
*
* @since 1.0
*
* @return bool True or false
*/
function atom_is_sticky(){
return(is_sticky() && is_home()); // sticky post? (we consider it sticky only if it's on the homepage)
}
/**
* Output the post thumbnail
*
* @since 1.0
*/
function atom_post_thumb(){
if(!atom_is_option_enabled('post_thumbs') || !atom_get_options('post_thumbs') || atom_is_asides() || atom_is_sticky()) return false;
$show_tip = (atom_thumbnails_only() || !atom_get_options('post_content'));
$tip_content = (atom_thumbnails_only() ? get_the_title() : strip_tags(get_the_excerpt()));
$title = ($show_tip ? $tip_content : sprintf(__('Permanent Link: %s', ATOM), the_title_attribute('echo=0')));
?>
's here
$ooutput = apply_filters('atom_social_media_links', $output);
if($output) echo '
'.$output.'
';
}
/**
* Output posts related to the current post, by tags
*
* @since 1.0
*
* @global $post object
* @global $id int
*
* @param int $post_id Optional. Post ID
* @param int $count Optional. Max. number of posts to retrieve
*
* @return string|bool A list of related posts (HTML), or false if no related posts were found
*
* @todo add fade effect on thumbnails
* @todo move the html to a template
*/
function atom_get_related_posts($post_id = NULL, $count = 5){
global $post, $id;
$post_id = (NULL === $post_id) ? $id : $post_id;
$output = '';
$tags = wp_get_post_tags($post_id);
if(!empty($tags)):
$tag_ids = array();
foreach($tags as $tag) $tag_ids[] = $tag->term_id;
$query = array('tag__in' => $tag_ids, 'post__not_in' => array($post_id), 'posts_per_page' => $count, 'caller_get_posts' => 1);
$related_posts = new WP_Query();
$related_posts->query($query);
if($related_posts):
$output = '
';
// If the front page is a page, add it to the exclude list
if (get_option('show_on_front') == 'page') $args['exclude'] = get_option('page_on_front');
$menu .= str_replace(array( "\r", "\n", "\t" ), '', wp_list_pages($args));
if($menu):
$menu = '