File: /www/wwwroot/www.213n.cn/wp-content/themes/rk-blogger/configure/common/utilities.php
<?php
/**
*
*/
//分页
function wbolt_the_posts_pagination($args = array())
{
echo wbolt_get_the_posts_pagination($args);
}
function wbolt_get_the_posts_pagination($args = array())
{
$navigation = '';
// Don't print empty markup if there's only one page.
if ($GLOBALS['wp_query']->max_num_pages > 1) {
$args = wp_parse_args($args, array(
'mid_size' => 5,
'prev_text' => _x('Prev', 'previous post', 'rk-blogger'),
'next_text' => _x('Next', 'next post', 'rk-blogger'),
'screen_reader_text' => __('Posts navigation', 'rk-blogger'),
));
// Make sure we get a string back. Plain is the next best thing.
if (isset($args['type']) && 'array' == $args['type']) {
$args['type'] = 'plain';
}
// Set up paginated links.
$links = paginate_links($args);
if ($links) {
$navigation = wbolt_navigation_markup($links, 'pagination', $args['screen_reader_text']);
}
}
return $navigation;
}
function wbolt_navigation_markup($links, $class = 'posts-navigation', $screen_reader_text = '')
{
if (empty($screen_reader_text)) {
$screen_reader_text = __('Posts navigation', 'rk-blogger');
}
$template = '
<a class="btn btn-load-more" id="J_loadMoreBtn"><span>' . __('More', 'rk-blogger') . '</span></a>
<div class="wb-navigation %1$s" role="navigation">
%3$s
</div>';
//Add this line
$template = apply_filters('navigation_markup_template', $template);
return sprintf($template, sanitize_html_class($class), esc_html($screen_reader_text), $links);
}
function wb_post_time($post = null, $echo = true)
{
$f = get_option('date_format');
$time = get_post_time('G', true, $post);
$diff = time() - $time;
if ($diff < DAY_IN_SECONDS) {
$time = human_time_diff($time) . ' ' . _x('Before', 'post time', 'rk-blogger');
} else {
$time = get_post_time($f, true, $post);
}
if ($echo) echo $time;
return $time;
}
/**
* 面包屑
*
* @param bool $current_page
* @param string $parents
*/
function wb_breadcrumbs($current_page = false, $parents = '', $wp_class = '')
{
$delimiter = '<i>></i>';
$current_before = '<strong>';
$current_after = '</strong>';
if (!is_home() && !is_front_page() || is_paged()) {
global $post;
echo '<div class="bread-crumbs"><div class="inner' . ($wp_class ? ' ' . $wp_class : '') . '">';
echo '<a class="item-home" href="' . home_url() . '" rel="home">首页</a> ' . $delimiter . ' ';
if ($parents) {
echo $parents;
}
if ($current_page) {
echo $current_page;
} elseif (is_category()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$parent_cat_id = $cat_obj->parent;
if ($parent_cat_id != 0) {
echo (get_category_parents($parent_cat_id, TRUE, ' ' . $delimiter . ' '));
}
echo $current_before;
single_cat_title();
echo $current_after;
} elseif (is_tax()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$parent_cat_id = $cat_obj->parent;
echo ' ' . $delimiter . ' ';
if ($parent_cat_id != 0) {
$args = array(
'separator' => ' ' . $delimiter . ' '
);
$cet_ret = get_term_parents_list($parent_cat_id, $cat_obj->taxonomy, $args);
if (!is_wp_error($cet_ret)) {
echo $cet_ret;
}
}
echo $current_before;
single_cat_title();
echo $current_after;
} elseif (is_day()) {
echo $current_before . get_the_time('Y') . '年' . get_the_time('F') . get_the_time('d') . $current_after;
} elseif (is_month()) {
echo $current_before . get_the_time('Y') . '年' . get_the_time('F') . $current_after;
} elseif (is_year()) {
echo $current_before . get_the_time('Y') . $current_after;
} elseif (is_single()) {
$pid = $post->ID;
$post_type = get_post_type($pid);
$cur_type_taxonomies = get_object_taxonomies($post_type);
$tax = $cur_type_taxonomies[0] ?? 0;
$cate = get_the_terms($pid, $tax);
/**
* 获取第1个分类的层级
*/
if (isset($cate[0]) && $cate[0]->parent) {
$args = array(
'separator' => ' ' . $delimiter . ' '
);
$cet_ret = get_term_parents_list($cate[0]->parent, $tax, $args);
if (!is_wp_error($cet_ret)) {
echo $cet_ret;
}
}
if ($cate) {
/**
* 列出所有所属分类
*/
foreach ($cate as $key => $item) {
if ($key > 0) echo ' <b>|</b> ';
echo '<a href=' . get_category_link($item->term_id) . '>' . $item->name . '</a>';
}
}
} elseif (is_page() && !$post->post_parent) {
echo $current_before;
the_title();
echo $current_after;
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_post($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $current_before;
the_title();
echo $current_after;
} elseif (is_search()) {
echo $current_before . ''' . get_search_query() . '' 的搜索结果' . $current_after;
} elseif (is_tag()) {
echo $current_before;
single_tag_title();
echo $current_after;
} elseif (is_author()) {
global $author;
$userdata = get_userdata($author);
echo $current_before . $userdata->display_name . $current_after;
} elseif (is_404()) {
echo $current_before . '404' . $current_after;
}
if (get_query_var('paged')) {
echo $current_before . '(';
echo __('Page', 'rk-blogger') . ' ' . get_query_var('paged');
echo ')' . $current_after;
}
echo '</div></div>';
}
}