📄 template-functions-post.php
字号:
echo '<a href="'.get_permalink().$i.'/">';
}
}
echo $j;
if (($i != $page) || ((!$more) && ($page==1)))
echo '</a>';
}
echo $after;
} else {
if ($more) {
echo $before;
$i=$page-1;
if ($i && $more) {
if ('' == get_settings('permalink_structure')) {
echo '<a href="'.get_permalink().'&page='.$i.'">';
} else {
echo '<a href="'.get_permalink().$i.'/">';
}
}
$i=$page+1;
if ($i<=$numpages && $more) {
if ('' == get_settings('permalink_structure')) {
echo '<a href="'.get_permalink().'&page='.$i.'">';
} else {
echo '<a href="'.get_permalink().$i.'/">';
}
}
echo $after;
}
}
}
}
function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
global $id, $post, $siteurl, $wpdb;
global $p, $posts, $posts_per_page, $s, $single;
if(($p) || ($posts_per_page == 1) || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category = '$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$limitprev--;
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");
if ($lastpost) {
$string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous;
if ($title == 'yes') {
$string .= wptexturize(stripslashes($lastpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
global $p, $posts, $id, $post, $siteurl, $wpdb;
global $time_difference, $single;
if(($p) || ($posts==1) || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category='$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
$limitnext--;
$nextpost = @$wpdb->get_row("SELECT ID,post_title FROM {$wpdb->posts} WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date ASC LIMIT $limitnext,1");
if ($nextpost) {
$string = '<a href="'.get_permalink($nextpost->ID).'">'.$next;
if ($title=='yes') {
$string .= wptexturize(stripslashes($nextpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
function next_posts($max_page = 0) { // original by cfactor at cooltux.org
global $siteurl, $p, $paged, $what_to_show, $pagenow;
if (empty($p) && ($what_to_show == 'paged')) {
$qstr = $_SERVER['QUERY_STRING'];
if (!empty($qstr)) {
$qstr = preg_replace("/&paged=\d{0,}/","",$qstr);
$qstr = preg_replace("/paged=\d{0,}/","",$qstr);
} elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
$_SERVER['REQUEST_URI']) ) {
$qstr = preg_replace("/^\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}/", "", $qstr);
$qstr = preg_replace("/\/$/", "", $qstr);
}
}
if (!$paged) $paged = 1;
$nextpage = intval($paged) + 1;
if (!$max_page || $max_page >= $nextpage) {
echo $siteurl.'/'.$pagenow.'?'.
($qstr == '' ? '' : $qstr.'&') .
'paged='.$nextpage;
}
}
}
function next_posts_link($label='Next Page »', $max_page=0) {
global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb;
if ($what_to_show == 'paged') {
if (!$max_page) {
$nxt_request = $request;
//if the query includes a limit clause, call it again without that
//limit clause!
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
}
if (!$paged)
$paged = 1;
$nextpage = intval($paged) + 1;
if (empty($p) && (empty($paged) || $nextpage <= $max_page)) {
echo '<a href="';
next_posts($max_page);
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
}
}
}
function previous_posts() { // original by cfactor at cooltux.org
global $siteurl, $p, $paged, $what_to_show, $pagenow;
if (empty($p) && ($what_to_show == 'paged')) {
$qstr = $_SERVER['QUERY_STRING'];
if (!empty($qstr)) {
$qstr = preg_replace("/&paged=\d{0,}/","",$qstr);
$qstr = preg_replace("/paged=\d{0,}/","",$qstr);
} elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
$_SERVER['REQUEST_URI']) ) {
$qstr = preg_replace("/^\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}/", "", $qstr);
$qstr = preg_replace("/\/$/", "", $qstr);
}
}
$nextpage = intval($paged) - 1;
if ($nextpage < 1) $nextpage = 1;
echo $siteurl.'/'.$pagenow.'?'.
($qstr == '' ? '' : $qstr.'&') .
'paged='.$nextpage;
}
}
function previous_posts_link($label='« Previous Page') {
global $p, $paged, $what_to_show;
if (empty($p) && ($paged > 1) && ($what_to_show == 'paged')) {
echo '<a href="';
previous_posts();
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
}
}
function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
global $p, $what_to_show, $request, $posts_per_page, $wpdb;
if (empty($p) && ($what_to_show == 'paged')) {
$nxt_request = $request;
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
if ($max_page > 1) {
previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
next_posts_link($nxtlabel, $max_page);
}
}
}
if (0) {
/*
* Post-meta: Custom per-post fields.
*/
function get_post_custom() {
global $id, $post_meta_cache;
return $post_meta_cache[$id];
}
function get_post_custom_keys() {
global $id, $post_meta_cache;
if (!is_array($post_meta_cache[$id]))
return;
if ($keys = array_keys($post_meta_cache[$id]))
return $keys;
}
function get_post_custom_values($key='') {
global $id, $post_meta_cache;
return $post_meta_cache[$id][$key];
}
// this will probably change at some point...
function the_meta() {
global $id, $post_meta_cache;
if ($keys = get_post_custom_keys()) {
echo "<ul class='post-meta'>\n";
foreach ($keys as $key) {
$values = array_map('trim',$post_meta_cache[$id][$key]);
$value = implode($values,', ');
echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n";
}
echo "</ul>\n";
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -