template-functions-links.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 528 行 · 第 1/2 页
PHP
528 行
<?phpfunction the_permalink() { echo apply_filters('the_permalink', get_permalink());}function permalink_link() { // For backwards compatibility echo apply_filters('the_permalink', get_permalink());}function permalink_anchor($mode = 'id') { global $post; switch ( strtolower($mode) ) { case 'title': $title = sanitize_title($post->post_title) . '-' . $id; echo '<a id="'.$title.'"></a>'; break; case 'id': default: echo '<a id="post-' . $post->ID . '"></a>'; break; }}function get_permalink($id = 0) { $rewritecode = array( '%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%' ); $post = &get_post($id); if ( $post->post_status == 'static' ) return get_page_link($post->ID); elseif ($post->post_status == 'attachment') return get_attachment_link($post->ID); $permalink = get_settings('permalink_structure'); if ( '' != $permalink && 'draft' != $post->post_status ) { $unixtime = strtotime($post->post_date); $category = ''; if ( strstr($permalink, '%category%') ) { $cats = get_the_category($post->ID); $category = $cats[0]->category_nicename; if ( $parent=$cats[0]->category_parent ) $category = get_category_parents($parent, FALSE, '/', TRUE) . $category; } $authordata = get_userdata($post->post_author); $author = $authordata->user_nicename; $date = explode(" ",date('Y m d H i s', $unixtime)); $rewritereplace = array( $date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name, ); return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post); } else { // if they're not using the fancy permalink option $permalink = get_settings('home') . '/?p=' . $post->ID; return apply_filters('post_link', $permalink, $post); }}function get_page_link($id = false) { global $post, $wp_rewrite; if ( !$id ) $id = $post->ID; $pagestruct = $wp_rewrite->get_page_permastruct(); if ( '' != $pagestruct ) { $link = get_page_uri($id); $link = str_replace('%pagename%', $link, $pagestruct); $link = get_settings('home') . "/$link/"; } else { $link = get_settings('home') . "/?page_id=$id"; } return apply_filters('page_link', $link, $id);}function get_attachment_link($id = false) { global $post, $wp_rewrite; $link = false; if (! $id) { $id = $post->ID; } $object = get_post($id); if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) ) { $parent = get_post($object->post_parent); $parentlink = get_permalink($object->post_parent); if (! strstr($parentlink, '?') ) $link = trim($parentlink, '/') . '/' . $object->post_name . '/'; } if (! $link ) { $link = get_bloginfo('home') . "/?attachment_id=$id"; } return apply_filters('attachment_link', $link, $id);}function get_year_link($year) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); $yearlink = $wp_rewrite->get_year_permastruct(); if ( !empty($yearlink) ) { $yearlink = str_replace('%year%', $year, $yearlink); return apply_filters('year_link', get_settings('home') . trailingslashit($yearlink), $year); } else { return apply_filters('year_link', get_settings('home') . '/?m=' . $year, $year); }}function get_month_link($year, $month) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); if ( !$month ) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600)); $monthlink = $wp_rewrite->get_month_permastruct(); if ( !empty($monthlink) ) { $monthlink = str_replace('%year%', $year, $monthlink); $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); return apply_filters('month_link', get_settings('home') . trailingslashit($monthlink), $year, $month); } else { return apply_filters('month_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2), $year, $month); }}function get_day_link($year, $month, $day) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); if ( !$month ) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600)); if ( !$day ) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600)); $daylink = $wp_rewrite->get_day_permastruct(); if ( !empty($daylink) ) { $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); return apply_filters('day_link', get_settings('home') . trailingslashit($daylink), $year, $month, $day); } else { return apply_filters('day_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day); }}function get_feed_link($feed='rss2') { global $wp_rewrite; $do_perma = 0; $feed_url = get_settings('siteurl'); $comment_feed_url = $feed_url; $permalink = $wp_rewrite->get_feed_permastruct(); if ( '' != $permalink ) { if ( false !== strpos($feed, 'comments_') ) { $feed = str_replace('comments_', '', $feed); $permalink = $wp_rewrite->get_comment_feed_permastruct(); } if ( 'rss2' == $feed ) $feed = ''; $permalink = str_replace('%feed%', $feed, $permalink); $permalink = preg_replace('#/+#', '/', "/$permalink/"); $output = get_settings('home') . $permalink; } else { if ( false !== strpos($feed, 'comments_') ) $feed = str_replace('comments_', 'comments-', $feed); $output = get_settings('home') . "/?feed={$feed}"; } return apply_filters('feed_link', $output, $feed);}function edit_post_link($link = 'Edit This', $before = '', $after = '') { global $post; if ( ! current_user_can('edit_post', $post->ID) ) return; if ( is_attachment() ) return; else $file = 'post'; $location = get_settings('siteurl') . "/wp-admin/{$file}.php?action=edit&post=$post->ID"; echo $before . "<a href=\"$location\">$link</a>" . $after;}function edit_comment_link($link = 'Edit This', $before = '', $after = '') { global $post, $comment; if ( ! current_user_can('edit_post', $post->ID) ) return; $location = get_settings('siteurl') . "/wp-admin/post.php?action=editcomment&comment=$comment->comment_ID"; echo $before . "<a href='$location'>$link</a>" . $after;}// Navigation linksfunction get_previous_post($in_same_cat = false, $excluded_categories = '') { global $post, $wpdb; if( !is_single() || is_attachment() ) return null; $current_post_date = $post->post_date; $join = ''; if ( $in_same_cat ) { $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id "; $cat_array = get_the_category($post->ID); $join .= ' AND (category_id = ' . intval($cat_array[0]->cat_ID); for ( $i = 1; $i < (count($cat_array)); $i++ ) { $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID); } $join .= ')'; } $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"; } } return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < '$current_post_date' AND post_status = 'publish' " . ( empty($GLOBALS["wp_xoops_author"])? "" : " AND post_author = " . intval($GLOBALS["wp_xoops_author"]) ) . " $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?