Viewing file: custom.lib.php (7.56 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php /** * Custom function to get current URL **/ global $data; function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } function king_debug($arr) { echo '<pre>'; print_r($arr); echo '</pre>'; }
function kingsize_pagination($pages = '', $range = 2) { $showitems = ($range * 2)+1;
global $paged,$data,$postParentPageID;
if (get_query_var('paged')) { $paged = get_query_var('paged'); } elseif (get_query_var('page')) { $paged = get_query_var('page'); } else { $paged = 1; }
if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } }
if(1 != $pages) { echo "<div class='pagination-container'>"; echo '<div id="pagination">'; if($paged > 1) echo "<div class='newer'><a href='".get_pagenum_link($paged - 1)."'>".__('Newer entries →', 'kslang')."</a></div>"; if ($paged < $pages) echo "<div class='older'><a href='".get_pagenum_link($paged + 1)."'>".__('← Older entries', 'kslang')."</a></div>";
echo "</div>\n"; echo "</div>\n"; }
}
function king_breadcrumbs() { $delimiter = '»'; $name = 'Home'; //text for the 'Home' link $currentBefore = '<span class="current">'; $currentAfter = '</span>'; if ( !is_home() && !is_front_page() || is_paged() ) { echo '<div id="crumbs">'; global $post; $home = get_template_directory_uri(); echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' '; if ( is_category() ) { global $wp_query; $cat_obj = $wp_query->get_queried_object(); $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')); echo $currentBefore . 'Archive by category ''; single_cat_title(); echo ''' . $currentAfter; } elseif ( is_day() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; echo $currentBefore . get_the_time('d') . $currentAfter; } elseif ( is_month() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo $currentBefore . get_the_time('F') . $currentAfter; } elseif ( is_year() ) { echo $currentBefore . get_the_time('Y') . $currentAfter; } elseif ( is_single() && !is_attachment() ) { $cat = get_the_category(); $cat = $cat[0]; echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_attachment() ) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' '; echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_page() && !$post->post_parent ) { echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_page() && $post->post_parent ) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' '; echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_search() ) { echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter; } elseif ( is_tag() ) { echo $currentBefore . 'Posts tagged ''; single_tag_title(); echo ''' . $currentAfter; } elseif ( is_author() ) { global $author; $userdata = get_userdata($author); echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter; } elseif ( is_404() ) { echo $currentBefore . 'Error 404' . $currentAfter; } if ( get_query_var('paged') ) { if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; echo __('Page', 'kslang') . ' ' . get_query_var('paged'); if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; } echo '</div>'; } }
function king_ago($timestamp){ $difference = time() - $timestamp; $periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade"); $lengths = array("60","60","24","7","4.35","12","10"); for($j = 0; $difference >= $lengths[$j]; $j++) $difference /= $lengths[$j]; $difference = round($difference); if($difference != 1) $periods[$j].= "s"; $text = "$difference $periods[$j] ago"; return $text; }
// Substring without losing word meaning and // tiny words (length 3 by default) are included on the result. // "..." is added if result do not reach original string length
function king_substr($str, $length, $minword = 3) { $sub = ''; $len = 0; foreach (explode(' ', $str) as $word) { $part = (($sub != '') ? ' ' : '') . $word; $sub .= $part; $len += strlen($part); if (strlen($word) > $minword && strlen($sub) >= $length) { break; } } return $sub . (($len < strlen($str)) ? '...' : ''); }
function _substr($str, $length, $minword = 3) { $sub = ''; $len = 0; foreach (explode(' ', $str) as $word) { $part = (($sub != '') ? ' ' : '') . $word; $sub .= $part; $len += strlen($part); if (strlen($word) > $minword && strlen($sub) >= $length) { break; } } return $sub . (($len < strlen($str)) ? '...' : ''); }
function get_the_content_with_formatting ($more_link_text = 'Read more', $stripteaser = 0, $more_file = '') { global $data; if($data['wm_blog_words_count']>0) $word_cnt = $data['wm_blog_words_count']; else $word_cnt = 600;
$content = get_the_content('', $stripteaser, $more_file); $content = strip_shortcodes($content); $content = str_replace(']]>', ']]>', $content); $content = '<p>'._substr(strip_tags($content), $word_cnt).'</p>'; $content.= '<a class="read_more" href="'.get_permalink().'" title="'.get_the_title().'">'.$more_link_text.'</a><!-- Read more link -->'; return $content; }
function image_from_description($data) { preg_match_all('/<img src="([^"]*)"([^>]*)>/i', $data, $matches); return $matches[1][0]; }
/* Change / add read more class of post*/ add_action( 'the_content_more_link', 'wpse63748_add_morelink_class', 10, 2 ); function wpse63748_add_morelink_class( $link, $text ) { return str_replace( 'more-link', 'posts-read-more', $link ); }
?>
|