WordPress模板的调用函数说明整理收藏

[wm_warn]注意
以下文件 可能和部分主题有冲突 修改前记得备份!!!
以下文件 可能和部分主题有冲突 修改前记得备份!!!
以下文件 可能和部分主题有冲突 修改前记得备份!!!
重要事情说三遍[/wm_warn]

WordPress模板基本文件

 
style.css 样式表文件
index.php 主页文件
single.php 日志单页文件
page.php 页面文件
archvie.php 分类和日期存档页文件
searchform.php 搜索表单文件
search.php 搜索页面文件
comments.php 留言区域文件(包括留言列表和留言框)
404.php 404错误页面
header.php 网页头部文件
sidebar.php 网页侧边栏文件
footer.php 网页底部文件

WordPress Header头部 PHP代码

<?php bloginfo(’name’); ?> 网站标题
<?php wp_title(); ?> 日志或页面标题
<?php bloginfo(’stylesheet_url’); ?> WordPress主题样式表文件style.css的相对地址
<?php bloginfo(’pingback_url’); ?> WordPress博客的Pingback地址
<?php bloginfo(’template_url’); ?> WordPress主题文件的相对地址
<?php bloginfo(’version’); ?> 博客的WordPress版本
<?php bloginfo(’atom_url’); ?> WordPress博客的Atom地址
<?php bloginfo(’rss2_url’); ?> WordPress博客的RSS2地址
<?php bloginfo(’url’); ?> WordPress博客的绝对地址
<?php bloginfo(’name’); ?> WordPress博客的名称
<?php bloginfo(’html_type’); ?> 网站的HTML版本
<?php bloginfo(’charset’); ?> 网站的字符编码格式

WordPress 主体模板 PHP代码

<?php the_content(); ?> 日志内容
<?php if(have_posts()) : ?> 确认是否有日志
<?php while(have_posts()) : the_post(); ?> 如果有,则显示全部日志
<?php endwhile; ?> 结束PHP函数”while”
<?php endif; ?> 结束PHP函数”if”
<?php get_header(); ?> header.php文件的内容
<?php get_sidebar(); ?> sidebar.php文件的内容
<?php get_footer(); ?> footer.php文件的内容
<?php the_time(’m-d-y’) ?> 显示格式为”02-19-08″的日期
<?php comments_popup_link(); ?> 显示一篇日志的留言链接
<?php the_title(); ?> 显示一篇日志或页面的标题
<?php the_permalink() ?> 显示一篇日志或页面的永久链接/URL地址
<?php the_category(’, ‘) ?> 显示一篇日志或页面的所属分类
<?php the_author(); ?> 显示一篇日志或页面的作者
<?php the_ID(); ?> 显示一篇日志或页面的ID
<?php edit_post_link(); ?> 显示一篇日志或页面的编辑链接
<?php get_links_list(); ?> 显示Blogroll中的链接
<?php comments_template(); ?> comments.php文件的内容
<?php wp_list_pages(); ?> 显示一份博客的页面列表
<?php wp_list_cats(); ?> 显示一份博客的分类列表
<?php next_post_link(’ %link ‘) ?> 下一篇日志的URL地址
<?php previous_post_link(’%link’) ?> 上一篇日志的URL地址
<?php get_calendar(); ?> 调用日历
<?php wp_get_archives() ?> 显示一份博客的日期存档列表
<?php posts_nav_link(); ?> 显示较新日志链接(上一页)和较旧日志链接(下一页)
<?php bloginfo(’description’); ?> 显示博客的描述信息

其它的一些WordPress模板代码

/%postname%/ 显示博客的自定义永久链接
<?php the_search_query(); ?> 搜索表单的值
<?php _e(’Message’); ?> 打印输出信息
<?php wp_register(); ?> 显示注册链接
<?php wp_loginout(); ?> 显示登入/登出链接
<!–next page–> 在日志或页面中插入分页
<!–more–> 截断日志
<?php wp_meta(); ?> 显示管理员的相关控制信息
<?php timer_stop(1); ?> 显示载入页面的时间
<?php echo get_num_queries(); ?> 显示载入页面查询

1.wordpress调用最新文章

WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下:

<?php get_archives(‘postbypost’, 10); ?> (显示10篇最新更新文章)
或者
<?php wp_get_archives(‘type=postbypost&limit=20&format=custom’); ?>

后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。具体的参数和使用方法你可 以参考官方的使用说明- wp_get_archvies。(fromat=custom也可以不要,默认以UL列表显示文章标题。)

补充: 通过WP的query_posts()函数也能调用最新文章列表, 虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。具体的使用方法也可以查看官方的说明。

2.wordpress调用随机文章

<?php
$rand_posts = get_posts(‘numberposts=10&orderby=rand’);
foreach( $rand_posts as $post ) :
?>
<!–下面是你想自定义的Loop–>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php endforeach; ?>

3.wordpress调用最新留言

<?php
global $wpdb;
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = ’1′ AND comment_type = ” AND
post_password = ”
ORDER BY comment_date_gmt DESC
LIMIT 10″;
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;   foreach ($comments as $comment) {
$output .= “n<li>”.strip_tags($comment->comment_author)
.”:” . ” <a href=”" . get_permalink($comment->ID) .
“#comment-” . $comment->comment_ID . “” title=”on ” .
$comment->post_title . “”>” . strip_tags($comment->com_excerpt)
.”</a></li>”;
}   $output .= $post_HTML;
echo $output;?>

4.wordpress调用相关文章

<?php
     
    $tags = wp_get_post_tags($post->ID);
     
    if ($tags) {
     
    $first_tag = $tags[0]->term_id;
     
    $args=array(
     
    ‘tag__in’ => array($first_tag),
     
    ‘post__not_in’ => array($post->ID),
     
    ‘showposts’=>10,
     
    ‘caller_get_posts’=>1
     
    );
     
    $my_query = new WP_Query($args);
     
    if( $my_query->have_posts() ) {
     
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
     
    <li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title();?> <?php comments_number(‘ ‘,’(1)’,'(%)’); ?></a></li>
    <?php
    endwhile;
    }
    }
    wp_reset_query();
    ?>

5.wordpress调用指定分类的文章

<?php $posts = get_posts( “category=4&numberposts=10″ ); ?>
<?php if( $posts ) : ?>
<ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<li>
<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

6.wordpress去评论者链接的评论输出

<?php
 
global $wpdb;
 
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,
 
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
 
comment_type,comment_author_url,
 
SUBSTRING(comment_content,1,14) AS com_excerpt
 
FROM $wpdb->comments
 
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
 
$wpdb->posts.ID)
 
WHERE comment_approved = ’1′ AND comment_type = ” AND
 
post_password = ”
 
ORDER BY comment_date_gmt DESC
 
LIMIT 10″;
 
$comments = $wpdb->get_results($sql);
 
$output = $pre_HTML;
 
foreach ($comments as $comment) {
 
$output .= “\n<li>”.strip_tags($comment->comment_author)
 
.”:” . ” <a href=\”" . get_permalink($comment->ID) .
“#comment-” . $comment->comment_ID . “\” title=\”on ” .
$comment->post_title . “\”>” . strip_tags($comment->com_excerpt)
.”</a></li>”;
}
$output .= $post_HTML;
echo $output;?>

7.wordpress调用含gravatar头像的评论输出

<?php
 
global $wpdb;
 
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,10) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ’1′ AND comment_type = ” AND comment_author != ‘郑 永’ AND post_password = ” ORDER BY comment_date_gmt DESC LIMIT 10″;
 
$comments = $wpdb->get_results($sql);
 
$output = $pre_HTML;
 
foreach ($comments as $comment) {
 
$output .= “\n<li>”.get_avatar(get_comment_author_email(‘comment_author_email’), 18). ” <a href=\”" . get_permalink($comment->ID) . “#comment-” . $comment->comment_ID . “\” title=\”" . $comment->post_title . ” 上的评论\”>”. strip_tags($comment->comment_author) .”: “. strip_tags($comment->com_excerpt) .”</a></li>”;
 
}
 
$output .= $post_HTML;
 
$output = convert_smilies($output);
 
echo $output;
 
?>

[wm_notice]上面代码把comment_author的值改成你的ID,18是头像大小,10是评论数量。[/wm_notice]

8.wordpress调用网站统计大全

1.日志总数

<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>

2.草稿数目

<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>

3.评论总数

<?php echo $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->comments”);?>

4.成立时间

<?php echo floor((time()-strtotime(“2008-8-18″))/86400); ?>

5.标签总数

<?php echo $count_tags = wp_count_terms(‘post_tag’); ?

6.页面总数

<?php $count_pages = wp_count_posts(‘page’); echo $page_posts = $count_pages->publish; ?>

7.分类总数

<?php echo $count_categories = wp_count_terms(‘category’); ?>

8.链接总数

<?php $link = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = ‘Y’”); echo $link; ?>

9.用户总数

<?php $users = $wpdb->get_var(“SELECT COUNT(ID) FROM $wpdb->users”); echo $users; ?>

10.最后更新

<?php $last = $wpdb->get_results(“SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = ‘post’ OR post_type = ‘page’) AND (post_status = ‘publish’ OR post_status = ‘private’)”);$last = date(‘Y-n-j’, strtotime($last[0]->MAX_m));echo $last; ?>

9.wordpress判断语句

判断是否是具体文章的页面

is_single()

判断是否是具体文章(id=2)的页面

is_single(’2′)

判断是否是具体文章(标题判断)的页面

is_single(’Beef Stew’)

判断是否是具体文章(slug判断)的页面

is_single(’beef-stew’)

是否留言开启

comments_open()

是否开启ping

pings_open()

是否是页面

is_page()

id判断,即是否是id为42的页面

is_page(’42′)

判断标题

is_page(’About Me’)

slug判断

is_page(’about-me’)

是否是分类

is_category()

id判断,即是否是id为6的分类

is_category(’6′)

分类title判断

is_category(’Cheeses’)

分类 slug判断

is_category(’cheeses’)

判断当前的文章是否属于分类5

in_category(’5′)

将所有的作者的页面显示出来

is_author()

显示author number为1337的页面

is_author(’1337′)

通过昵称来显示当前作者的页面

is_author(’Elite Hacker’)

下面是通过不同的判断实现以年、月、日、时间等方式来显示归档

is_date()
 
is_year()
 
is_month()
 
is_day()
 
is_time()

判断当前是否是归档页面

is_archive()

判断是否是搜索

is_search()

判断页面是否404

is_404()

判断是否翻页,比如你当前的blog是https://www.dujia520.cnhttps://www.dujia520.cn?paged=2的时候,这个判断将返 回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界面,

例如:

<?php if(is_single()):?>
     
    //这里写你想显示的内容,包括函数
     
    <?php endif;?>

或者

    <?php if(is_home() && !is_paged() ):?>
     
    //这里写你想显示的内容,包括函数
     
    <?php endif;?>

10.wordpress 非插件调用评论表情

<!–smilies–>
<?php
 
function wp_smilies() {
 
global $wpsmiliestrans;
 
if ( !get_option(‘use_smilies’) or (empty($wpsmiliestrans))) return;
 
$smilies = array_unique($wpsmiliestrans);
 
$link=”;
 
foreach ($smilies as $key => $smile) {
 
$file = get_bloginfo(‘wpurl’).’/wp-includes/images/smilies/’.$smile;
 
$value = ” “.$key.” “;
 
$img = “<img src=\”{$file}\” alt=\”{$smile}\” />”;
 
$imglink = htmlspecialchars($img);
 
$link .= “<a href=\”#commentform\” title=\”{$smile}\” οnclick=\”document.getElementById(‘comment’).value += ‘{$value}’\”>{$img}</a>&nbsp;”;
 
}
 
echo ‘<div>’.$link.’</div>’;
 
}
 
?>
 
<?php wp_smilies();?>
 
<!–smilies—>

[wm_notice]将以上代码复制到 comments.php 中合适的位置即可(修改前记得备份,以上文件 可能和部分主题有冲突)[/wm_notice]

【wordpress优化】一段代码去掉谷歌字体

介绍

自从谷歌被墙了,就连谷歌字体也链接不上了,但是WordPress后台和一些外国主题都使用了谷歌字体,谷歌字体链接不上自然就导致了WordPress奇慢无比,所以在国内使用WordPress做的第一件事就是去掉谷歌字体。

使用方法

将以下代码添加到当前使用的主题的functions.php文件中即可。

代码

//去除谷歌字体
    if (!function_exists('remove_wp_open_sans')) :
    function remove_wp_open_sans() {
    wp_deregister_style( 'open-sans' );
    wp_register_style( 'open-sans', false );
    }
  // 前台删除Google字体CSS
    add_action('wp_enqueue_scripts', 'remove_wp_open_sans');
  // 后台删除Google字体CSS
    add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
  endif;

【wordpress代码】给博客添加文章字数统计代码

代码实现前台文章界面显示文章字数统计代码 之前只能在后台显示,现在前台也就可以显示了

使用方法

functions.php文件中加入以下代码-有些主题会是在functions-theme.php文件中。

代码

//字数统计
function count_words ($text) {
global $post;
if ( '' == $text ) {
$text = $post->post_content;
if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '本文共' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . '个字';
return $output;
}
}

调用代码

<?php echo count_words ($text); ?>

提示:放在文章配置文件(合适的位置就可以了)

【wordpress代码】纯代码实现压缩优化网站速度

使用方法

将以下代码复制到functions.php文件中,有的主题在functions-theme.php文件中。

代码

/*
WordPress网页代码压缩
*/
function wp_compress_html(){
    function wp_compress_html_main ($buffer){
        $initial=strlen($buffer);
        $buffer=explode("", $buffer);
        $count=count ($buffer);
        for ($i = 0; $i <= $count; $i++){
            if (stristr($buffer[$i], '')) {
                $buffer[$i]=(str_replace("", " ", $buffer[$i]));
            } else {
                $buffer[$i]=(str_replace("\t", " ", $buffer[$i]));
                $buffer[$i]=(str_replace("\n\n", "\n", $buffer[$i]));
                $buffer[$i]=(str_replace("\n", "", $buffer[$i]));
                $buffer[$i]=(str_replace("\r", "", $buffer[$i]));
                while (stristr($buffer[$i], '  ')) {
                    $buffer[$i]=(str_replace("  ", " ", $buffer[$i]));
                }
            }
            $buffer_out.=$buffer[$i];
        }
        $final=strlen($buffer_out);   
        $savings=($initial-$final)/$initial*100;   
        $savings=round($savings, 2);   
    return $buffer_out;
}
ob_start("wp_compress_html_main");
}
add_action('get_header', 'wp_compress_html');

然后刷新网页就OK了。那么如果我们要一些地方不要压缩,该如何做呢?

格式

<!--wp-compress-html--><!--wp-compress-html no compression-->

 

【wordpress代码】让代码实现一键获取网站的全部链接


这个是一键获取网站全部链接,获取文章页面链接 单页面链接 博客分类页,标签页等等,适合网站批量提交收录吧

效果图

使用方法

1.创建个PHP文件,名字随意,(比如:kkk.php)将以下面代码复制到all.php中

2上传至网站根目录,然后访问域名/all.php就可以了!

代码

<?php
require('./wp-blog-header.php');
header("Content-type: text/txt");
header('HTTP/1.1 200 OK');
$posts_to_show = 1000; // 获取文章数量
?>
<?php echo 'http://'.$_SERVER['HTTP_HOST']; ?><?php echo "\n"; ?>
<?php
/* 文章页面 */
header("Content-type: text/txt");
$myposts = get_posts( "numberposts=" . $posts_to_show );
foreach( $myposts as $post ) {
the_permalink();
echo "\n";
}
?>
<?php
/* 单页面 */
$mypages = get_pages();
if(count($mypages) > 0) {
foreach($mypages as $page) {
echo get_page_link($page->ID);
echo "\n";
}
}
?>
<?php
/* 博客分类 */
$terms = get_terms('category', 'orderby=name&hide_empty=0' );
$count = count($terms);
if($count > 0){
foreach ($terms as $term) {
echo get_term_link($term, $term->slug);
echo "\n";
}
}
?>
<?php
/* 标签(可选) */
$tags = get_terms("post_tag");
foreach ( $tags as $key => $tag ) {
$link = get_term_link( intval($tag->term_id), "post_tag" );
if ( is_wp_error( $link ) ) {
return false;
$tags[ $key ]->link = $link;
}
echo $link;
echo "\n";
}
?>

 

【WordPress教程】禁止纯英文和日文的评论


将一下代码复制到functions.php中即可。提示:只要是全局调用文件就可以啦

代码

// 屏蔽纯英文评论和纯日文
function refused_english_comments($incoming_comment) {
$pattern = '/[一-龥]/u';
// 禁止全英文评论
if(!preg_match($pattern, $incoming_comment['comment_content'])) {
wp_die( "您的评论中必须包含汉字!" );
}
$pattern = '/[あ-んア-ン]/u';
// 禁止日文评论
if(preg_match($pattern, $incoming_comment['comment_content'])) {
wp_die( "评论禁止包含日文!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'refused_english_comments');

评论提交时,通过正则表达式匹配评论内容,如果评论是纯英文或者包含了日文,则跳转到提示页面。

【WordPress代码】实现自助申请友链功能与自动审核


今天给大家介绍下如何在wordpress程序中添加自动申请友情链接和后台管理人员查看友情链接的审核。下面教程开始

效果图

代码如下

如果你是vieu主题就恭喜你,可以直接去底部下载PHP替换即可,如果你是其他主题可以跟着我的操作一部一部来完成。

<?php
/*
Template Name: 自助申请友链
* 提示:友情链接,需在后台审核
*/
?>
<?php
if( isset($_POST['blink_form']) && $_POST['blink_form'] == 'send'){
global $wpdb;

// 表单变量初始化
$link_name = isset( $_POST['blink_name'] ) ? trim(htmlspecialchars($_POST['blink_name'], ENT_QUOTES)) : '';
$link_url = isset( $_POST['blink_url'] ) ? trim(htmlspecialchars($_POST['blink_url'], ENT_QUOTES)) : '';
$link_description = isset( $_POST['blink_lianxi'] ) ? trim(htmlspecialchars($_POST['blink_lianxi'], ENT_QUOTES)) : ''; // 联系方式
$link_target = "_blank";
$link_visible = "N"; // 表示链接默认不可见

// 表单项数据验证
if ( empty($link_name) || mb_strlen($link_name) > 20 ){
wp_die('连接名称必须填写,且长度不得超过30字');
}

if ( empty($link_url) || strlen($link_url) > 60 || !preg_match("/^(https?:\/\/)?(((www\.)?[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)?\.([a-zA-Z]+))|(([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5]))(\:\d{0,4})?)(\/[\w- .\/?%&=]*)?$/i", $link_url)) { //验证url
wp_die('链接地址必须填写');
}

$sql_link = $wpdb->insert(
$wpdb->links,
array(
'link_name' => '【待审核】--- '.$link_name,
'link_url' => $link_url,
'link_target' => $link_target,
'link_description' => $link_description,
'link_visible' => $link_visible
)
);

$result = $wpdb->get_results($sql_link);

wp_die('亲,友情链接提交成功,【等待站长审核中】!<a href="/blinks/">点此返回</a>', '提交成功');

}

get_header();
?>

<div id="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="col-md-10 col-md-offset-2 view clearfix">
<?php if(function_exists('cmp_breadcrumbs')) cmp_breadcrumbs();?>

<p class="mt20">欢迎同类站点与本站交换友情链接,要求有权重有排名,收录良好的,内容健康,内容相关更佳。</p>

<p class="mt20"><strong>友链自助申请须知</strong></p>

<p>&#x2714; 申请前请先加上本站链接;</p>

<p>&#x2714; 网站域名必须是一级域名,非一级域名的网站暂不考虑;</p>

<p>&#x2714; 稳定更新,每月至少发布1篇文章,最好是建站半年以上;</p>

<p>&#x2714; 禁止一切产品营销、广告联盟类型的网站,优先通过同类原创、内容相近的网站;</p>

<p>&#x2714; 网站内容一定要健康积极向上,凡内容污秽不堪的、反动反共的、宣扬暴力的、广告挂马的都将不会通过申请。</p>

<p class="mt20"><strong>其他</strong></p>

<p>博主会不定期访问友链,如果遇到网站长时间打不开、网站被降权,内容不符合条件等情况的话,将会撤销该友链!</p>
<p>如果申请后,长时间未通过审核,有可能是博主太忙未看到,可以通过右侧QQ联系告知我,谢谢~</p>

<p class="mt20"><strong>本站链接信息</strong></p>

<p>名称:记磊博客</p>

<p>网址:https://www.ly522.com/</p>

<!--表单开始-->
<form method="post" class="mt20" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">

<div class="form-group">
<label for="blink_name"><font color="red">*</font> 链接名称:</label>
<input type="text" size="40" value="" class="form-control" id="blink_name" placeholder="请输入链接名称" name="blink_name" />
</div>

<div class="form-group">
<label for="blink_url"><font color="red">*</font> 链接地址:</label>
<input type="text" size="40" value="" class="form-control" id="blink_url" placeholder="请输入链接地址" name="blink_url" />
</div>

<div class="form-group">
<label for="blink_lianxi">联系QQ:</label>
<input type="text" size="40" value="" class="form-control" id="blink_lianxi" placeholder="请输入联系QQ" name="blink_lianxi" />
</div>

<div>
<input type="hidden" value="send" name="blink_form" />
<button type="submit" class="btn btn-primary">提交申请</button>
<button type="reset" class="btn btn-default">重填</button>
(提示:带有<font color="red">*</font>,表示必填项~)
</div>
</form>
<!--表单结束-->

</article>
<?php endwhile; else: ?>
<?php endif; ?>
</div>

<?php get_footer(); ?>

使用方法

1、在你wp博客主题的目录下新建一个名为blinks.php的文件;

2、复制以下代码至blinks.php中:

3、保存,最后进入WordPress管理后台 – 页面 – 添加新页面,标题为自助友链申请(你也可以自己起名),内容填上链接说明等,右侧选择模板,选择“自助申请友链”,发布。

4、自己在需要在页面中增加加入代码,如下

<a href="https://www.dujia520.cn/shengqyq/">我要申请</a>

至于如何展示链接的话,可以试试WordPress自带的函数wp_list_bookmarks()

提示:说明:其中主要部分就是get_header()前面的所有代码,以及form表单中的所有代码。部分文字描述代码也可以放在后台编辑器中,我这里并没有放哦~ 还有一点需要注意的是:后台不会高亮出哪个是刚提交的链接,你只能筛选或者搜索“待审核”找到它。

wordpress后台-添加审核链接按钮

找到wp-admin目录下的link-manager.php,在86行【Tips: 如果找不到就搜索“link-add.php”,找到这行】后面添加如下代码:

<a href="/wp-admin/link-manager.php?s=待审核&action=-1&cat_id=0&action2=-1" style="color:red;margin-left:5px;">查看待审核链接</a>

效果图

替换路径为vieu/pages/links.php

vieu主题替换下载

【WordPress】免费开启CDN与https回源设置-又拍云

没接触过又拍云的或许不知道,其实它的功能挺多的,但对于我们个人博客来说,够用就行。主要是不用花钱,能免费就免费
下面给大家纤细说说,对于个人博客涉及到的操作简要说一下:

如何开启CDN

  • 创建CDN
  • 服务器名称:可以写英文或中文都可以的(尽量简单一点)
  • 加速域名:绑定自己要加速的域名
  • 应用场景:其中一个都可以
  • 源站设置:源站地址:自己服务器地址ip 、端口默认即可(根据自己的情况而定)
  • 加速域名:全球加速

最后点击完成即可(使用又拍云cdn必须备案,这里cname解析又拍云给出的域名。)

https回源设置CDN

1.配置回源,填写你的主机ip

2.缓存配置(如果你们和我一样也是用的WordPress程序可以按照我这个去设置)

对于其他程序博客,静态资源肯定是要缓存的,比如图片,js文本。这些又拍云都有提供文本,点击添加就行,其他的就根据你自己的需求添加。时间可以设置更久看自己而定。
3.最后点击刷新(停留一分钟左右就可以访问了)

又拍云也提供免费的ssl,直接申请,也可上传别的证书,
这里放个推荐链接:邀请注册每个月有15G流量,对于小站基本够用。