-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfunctions.php
More file actions
152 lines (126 loc) · 5.28 KB
/
Copy pathfunctions.php
File metadata and controls
152 lines (126 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
// 是否展示评论(从主题层面避免评论的展示,你懂得)
$showComment = false;
// 分页函数
function getPageNav($query_string)
{
global $posts_per_page, $paged;
$my_query = new WP_Query($query_string . "&posts_per_page=-1");
$total_posts = $my_query->post_count;
if (empty($paged)) $paged = 1;
$prev = $paged - 1;
$next = $paged + 1;
$range = 4; // only edit this if you want to show more page-links
$showitems = ($range * 2) + 1;
$pages = ceil($total_posts / $posts_per_page);
if (1 != $pages) {
echo "<div class='pagination'>";
echo ($paged > 2 && $paged + $range + 1 > $pages && $showitems < $pages) ? "<a href='" . get_pagenum_link(1) . "'>首页</a>" : "";
echo ($paged > 1 && $showitems < $pages) ? "<a href='" . get_pagenum_link($prev) . "'>上一页</a>" : "";
for ($i = 1; $i <= $pages; $i++) {
if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems)) {
echo ($paged == $i) ? "<span class='current'>" . $i . "</span>" : "<a href='" . get_pagenum_link($i) . "' class='inactive' >" . $i . "</a>";
}
}
echo ($paged < $pages && $showitems < $pages) ? "<a href='" . get_pagenum_link($next) . "'>下一页</a>" : "";
echo ($paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages) ? "<a href='" . get_pagenum_link($pages) . "'>末页</a>" : "";
echo "</div>\n";
}
}
// 面包屑导航
function getBreadcrumbs()
{
global $wp_query;
if (!is_home()) {
// Add the Home link
echo '<li><a href="' . get_settings('home') . '">主页</a></li>';
if (is_category()) {
$catTitle = single_cat_title("", false);
$cat = get_cat_ID($catTitle);
echo "<li>»" . get_category_parents($cat, TRUE, "") . "</li>";
} elseif (is_tag()) {
$tag = get_queried_object();
echo "<li> » <a href='".get_tag_link($tag->term_id)."'>".single_tag_title("",false)."</a></li>";
} elseif (is_archive() && !is_category()) {
echo "<li>归档</li>";
} elseif (is_search()) {
echo "<li> » <a href='#'>搜索结果</a></li>";
} elseif (is_404()) {
echo "<li>找不到内容</li>";
} elseif (is_single()) {
$category = get_the_category();
$category_id = get_cat_ID($category[0]->cat_name);
echo '<li>»' . get_category_parents($category_id, TRUE, "") . '</li>';
// echo '<a href="'.get_permalink().'">'.the_title('','', FALSE) ."</a></li>";
} elseif (is_page()) {
$post = $wp_query->get_queried_object();
if ($post->post_parent == 0) {
echo "<li> » <a href='" . get_permalink() . "'>" . the_title('', '', FALSE) . "</a></li>";
} else {
$title = the_title('', '', FALSE);
$ancestors = array_reverse(get_post_ancestors($post->ID));
array_push($ancestors, $post->ID);
foreach ($ancestors as $ancestor) {
if ($ancestor != end($ancestors)) {
echo '<li> » <a href="' . get_permalink($ancestor) . '">' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</a></li>';
} else {
echo '<li> » ' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</li>';
}
}
}
}
}
}
// 评论列表
function getComment($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
?>
<tr class="comment-list" id="li-comment-<?php comment_ID(); ?>">
<td><?php if (function_exists('get_avatar') && get_option('show_avatars')) {
echo get_avatar($comment, 48);
} ?></td>
<td class="author"><?php printf(__('%s'), get_comment_author_link()); ?></td>
<td id="comment-<?php comment_ID(); ?>" title="留言时间:<?php echo get_comment_time('Y年m月d日 H:i'); ?>">
<?php comment_text(); ?>
<?php if ($comment->comment_approved == '0') : ?>
<em>你的评论正在审核,稍后会显示出来!</em><br/>
<?php endif; ?>
</td>
</tr>
<?php
}
if (function_exists('register_nav_menu')) {
register_nav_menu('category_nav_menu', '主导航菜单 - 分类');
register_nav_menu('about_nav_menu', '主导航菜单 - 关于');
}
// 首页标签
function getIndexTags()
{
$args = array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 15,
);
$tags = get_tags($args);
if (count($tags) > 0):
echo '<div id="links">';
foreach ($tags as $tag) {
echo '<li><a href="' . get_tag_link($tag->term_id) . '">' . $tag->name .'('. $tag->count .')'. '</a></li>';
}
echo '</div>';
endif;
}
// 内页标签
function getSingleTags($postId)
{
$tags = get_the_tags($postId);
if (count($tags) > 0):
echo '<div id="links"> <span>相关标签:</span>';
foreach ($tags as $tag) {
echo '<li><a href="' . get_tag_link($tag->term_id) . '">' . $tag->name .'('. $tag->count .')'. '</a></li>';
}
echo '</div>';
endif;
}
?>