![图片[1]- 子比主题-友情链接自助检测+api自建(修复版)](https://www.dh139.cn/wp-content/uploads/2025/04/1-27-1024x510.jpg)
友情链接页面代码
(复制后直接放入路径 /wp-content/themes/zibll/pages/links.php文件里面,记得先删除原来的代码) 里面图片API自行更换,或者使用本站官方图片随机接口
下面代码放入 links.php里面,记得删除原来的代码,
<?php
function zib_page_links()
{
$post_ID = get_queried_object_id();
$args_category = zib_get_post_meta($post_ID, 'page_links_category', true);
if (!$args_category) {
return;
}
$args_orderby = zib_get_post_meta($post_ID, 'page_links_orderby', true);
$args_order = zib_get_post_meta($post_ID, 'page_links_order', true);
$args_limit = zib_get_post_meta($post_ID, 'page_links_limit', true);
$page_links_style = zib_get_post_meta($post_ID, 'page_links_style', true);
$args_go_s = zib_get_post_meta($post_ID, 'page_links_go_s', true);
$args_blank_s = zib_get_post_meta($post_ID, 'page_links_blank_s', true);
$page_links_submit_s = zib_get_post_meta($post_ID, 'page_links_submit_s', true);
$page_links_submit_title = $page_links_submit_s ? zib_get_post_meta($post_ID, 'page_links_submit_title', true) : '';
$is_mobile = wp_is_mobile();
$links_con = '';
if (is_array($args_category) && count($args_category) > 1) {
$link_cat_con = '';
$link_cat_nav = '';
foreach ($args_category as $cat_id) {
$args = array(
'orderby' => $args_orderby ? $args_orderby : 'name', //排序方式
'order' => $args_order ? $args_order : 'ASC', //升序还是降序
'limit' => $args_limit ? (int) $args_limit : -1, //最多显示数量
'category' => $cat_id,
);
$_link = zib_links_box(get_bookmarks($args), $page_links_style, false, $args_go_s, $args_blank_s);
if ($_link) {
$_id = 'links-' . $cat_id;
$get_term = get_term($cat_id);
if (!isset($get_term->term_id)) {
continue;
}
$_title = get_term($cat_id)->name;
$link_cat_con .= '<div class="mb20 links-cat-box"><div class="links-cat-header"><div class="title-theme"><div id="' . $_id . '">' . $_title . '</div></div></div><div class="links-box links-style-' . $page_links_style . '">' . $_link . '</div></div>';
$link_cat_nav .= '<li class="n-H2"><a class="text-ellipsis" href="#' . $_id . '">' . $_title . '</a></li>';
}
}
$page_links_submit_btn_nav = $page_links_submit_s ? '<div class="link-nav-submit"><a class="padding-h10 hollow but c-theme btn-block text-ellipsis" href="#submit-links-modal" data-toggle="modal">' . $page_links_submit_title . '</a></div>' : '';
$page_links_submit_btn_con = $page_links_submit_s ? '<div class="link-cat-submit"><a class="padding-h10 hollow but c-theme btn-block text-ellipsis" href="#submit-links-modal" data-toggle="modal">' . $page_links_submit_title . '</a></div>' : '';
$links_con = '<div class="fixed-wrap"><div class="fixed-wrap-nav affix-header-sm affix link-nav-box tab-auto-center-sm" offset-top="'.($is_mobile ? '-8':'').'" offset-bottom="'.($is_mobile ? '20':'-30').'"><div class="zib-widget"><ul class="nav list-inline scroll-x mini-scrollbar tab-nav-theme">' . $link_cat_nav . '</ul></div>' . $page_links_submit_btn_nav . '</div><div class="fixed-wrap-content">' . $link_cat_con . $page_links_submit_btn_con . '</div></div>';
} else {
$args = array(
'orderby' => $args_orderby ? $args_orderby : 'name', //排序方式
'order' => $args_order ? $args_order : 'ASC', //升序还是降序
'limit' => $args_limit ? (int) $args_limit : -1, //最多显示数量
'category' => $args_category, //以逗号分隔的类别ID列表
);
$page_links_submit_btn_con = $page_links_submit_s ? '<div class="mt20"><a class="padding-h10 hollow but c-theme btn-block text-ellipsis" href="#submit-links-modal" data-toggle="modal">' . $page_links_submit_title . '</a></div>' : '';
$links_con = '<div class="links-box links-style-' . $page_links_style . '">' . zib_links_box(get_bookmarks($args), $page_links_style, false, $args_go_s, $args_blank_s) . '</div>' . $page_links_submit_btn_con;
}
$html = '';
if ($links_con) {
$html = '<div class="links-page-container mb20">' . $links_con . '</div>';
} elseif (is_super_admin()) {
$html = '<div class="mb20"><a class="author-minicard links-card radius8" href="' . admin_url('link-manager.php') . '" target="_blank">添加链接</a></div>';
} else {
$html = '<div class="author-minicard links-card radius8 mb20">暂无链接</div>';
}
return $html;
}
function zib_link_get_search_cover()
{
global $post;
$post_id = $post->ID;
if (!zib_get_post_meta($post_id, 'page_links_search_s', true)) {
return;
}
$search_types = zib_get_post_meta($post_id, 'page_links_search_types', true);
if (!$search_types) {
return;
}
$search_types_args = array(
'self' => array(
'name' => '站内',
'input_name' => 's',
'url' => home_url(),
),
'baidu' => array(
'name' => '百度',
'input_name' => 'wd',
'url' => 'https://www.baidu.com/s',
),
'google' => array(
'name' => '谷歌',
'input_name' => 'q',
'url' => 'https://www.google.com/search?',
),
'bing' => array(
'name' => '必应',
'input_name' => 'q',
'url' => 'https://cn.bing.com/search?',
),
'sogou' => array(
'name' => '搜狗',
'input_name' => 'query',
'url' => 'https://www.sogou.com/web?',
),
'360' => array(
'name' => '360',
'input_name' => 'q',
'url' => 'https://www.so.com/s?',
),
);
$type_nav = '';
$type_con = '';
//默认action
$i = 0;
foreach ($search_types as $k) {
if (isset($search_types_args[$k])) {
$type_nav .= '<li class="' . ($i === 0 ? ' active' : '') . '"><a class="" data-toggle="tab" data-target="#link-page-' . $post_id . '-' . $k . '" href="javascript:;">' . $search_types_args[$k]['name'] . '</a></li>';
$type_con .= '<div class="tab-pane' . ($i === 0 ? ' in active' : '') . '" id="link-page-' . $post_id . '-' . $k . '" >
<form method="get" target="_blank" class="padding-10 search-form" action="' . $search_types_args[$k]['url'] . '">
<div class="line-form blur-bg">
<div class="search-input-text">
<input type="text" name="' . $search_types_args[$k]['input_name'] . '" class="line-form-input" tabindex="1" value=""><i class="line-form-line"></i>
<div class="scale-placeholder">' . $search_types_args[$k]['name'] . '搜索</div>
<div class="abs-right muted-color"><button type="submit" tabindex="2" class="null"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-search"></use></svg></button>
</div>
</div>
</div>
</form>
</div>';
$i++;
}
}
$title = get_the_title($post);
$img = '';
$post_thumbnail_id = get_post_thumbnail_id($post_id);
if ($post_thumbnail_id) {
$image = wp_get_attachment_image_src($post_thumbnail_id, 'full');
$img = !empty($image[0]) ? $image[0] : '';
}
if (!$img) {
$img = zib_get_post_meta($post_id, 'thumbnail_url', true);
}
$src = ZIB_TEMPLATE_DIRECTORY_URI . '/img/thumbnail-lg.svg';
$img = $img ? $img : _pz('page_header_cover_img', ZIB_TEMPLATE_DIRECTORY_URI . '/img/user_t.jpg');
$search = '<div class="header-slider-search abs-center"><div class="header-slider-search-more text-center before"><div class="em14 font-bold mb10">' . $title . '</div></div>
<div class="search-input">
<div class="flex jc"><ul class="list-inline scroll-x mini-scrollbar tab-nav-theme">' . $type_nav . '</ul></div>
<div class="tab-content">' . $type_con . '</div>
</div>
</div>';
$html = '<div class="page-cover theme-box radius8 main-shadow link-page-search-cover">
<img ' . (zib_is_lazy('lazy_cover', true) ? 'class="fit-cover no-scale lazyload" src="' . $src . '" data-src="' . $img . '"' : 'class="fit-cover no-scale" src="' . $img . '"') . '>
' . $search . '</div>';
return $html;
}
//开始输出
$post_id = get_queried_object_id();
$page_id = $post_id;
$header_style = zib_get_page_header_style();
$page_links_content_s = zib_get_post_meta($post_id, 'page_links_content_s', true);
$page_links_content_position = zib_get_post_meta($post_id, 'page_links_content_position', true);
$page_links_submit_s = zib_get_post_meta($post_id, 'page_links_submit_s', true);
$content_style = zib_get_page_content_style($post_id);
//小工具容器
$widgets_register_container = array();
if (get_post_meta($post_id, 'widgets_register', true)) {
$widgets_register_container = (array) get_post_meta($post_id, 'widgets_register_container', true);
}
get_header();
//顶部全宽度小工具
if ($widgets_register_container && in_array('top_fluid', $widgets_register_container)) {
echo '<div class="container fluid-widget">';
dynamic_sidebar('page_top_fluid_' . $post_id);
echo '</div>';
}
?>
<style>
.admin-btn{background: #8486f8;padding: 2px 10px;color: #fff;border-radius: 4px;}
.admin-guanli{visibility:hidden;position: absolute;min-width: 80px;background-color: var(--main-bg-color);padding: 10px 5px;z-index: 99;border-radius: var(--main-radius);box-shadow: 0 0 10px rgba(0,0,0,.1);right: -40px;margin-top: -40px;}
.xy_hide:hover>.admin-guanli{visibility:unset;}
.xy_hide:hover>.admin-btn{color: #fff;background: #6d6fd8;}
.f12{font-size:12px;}
.xypro_describe {position: relative;border: 1px dashed #dcdfe6;line-height: 26px;}
.xypro_describe_title {position: absolute;top: 0;left: 8px;-webkit-transform: translateY(-50%);transform: translateY(-50%);background: #fff;padding: 0 5px;color: #303133;font-weight: 500;max-width: 200px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
.xypro_describe_content{color: #606266;padding: 18px 15px 30px;}
.yq{width: 100%;max-width: 100%;table-layout: fixed;color: #909399;margin-bottom: 18px;border-top: 1px solid #ebeef5;border-left: 1px solid #ebeef5;}
.yq thead th {font-weight: 500;background: #ebeef5;text-align: center;padding: 8px;border-bottom: 1px solid #ebeef5;border-right: 1px solid #ebeef5;}
.yq_link td {text-align: center;padding: 8px;border-bottom: 1px solid #ebeef5;border-right: 1px solid #ebeef5;text-overflow: ellipsis;
white-space: nowrap;overflow: hidden;}
.xy_li {text-align: center;font-size: 16px;line-height: 30px;}
.xy_li::marker {content: "#" counter(list-item) " ";color: var(--theme-color);}
.xy-mask {background-color: rgba(0,0,0,.5);}
.xy_height_hide{height: 300px;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;}
.xy_height_hide_p{background: linear-gradient(180deg,hsla(0,0%,100%,0),#fff);width: 100%;z-index: 1;position: absolute;bottom: 0;margin: 0;height: 100px;}
.xy_height_hide_p2{text-align: center;bottom: 0;z-index: 2;position: absolute;left: 0;right: 0;cursor: pointer !important;}
.xy-more-btn{width: 20px;height: 20px;background-color: var(--main-bg-color);border: 1px solid rgb(237, 237, 237);border-radius: 50%;line-height: 18px;}
code{font-family: "lovely";}
.xy_callout ol li::marker {content: "#" counter(list-item) " ";color: var(--theme-color);}
.xy_callout {padding: 20px;border: 1px solid #e4e4e4;border-left-width: 5px;border-radius: 6px;line-height: 30px;font-weight: 600;border-left-color: var(--theme-color);}
.xy_content>h5{margin: 0;font-weight:600;font-size: 24px;line-height: 32px;padding:20px 0;text-align: center;}
.xy_checkbox:checked{background:var(--theme-color);-webkit-appearance: none;position: relative;border-radius: 2px;width: 15px;height: 15px;vertical-align: -2px;}
.xy_content h5:before {content: '「';color: var(--theme-color);font-weight: 600;margin-left: 5px;}
.xy_content h5:after {content: '」';color: var(--theme-color);font-weight: 600;margin-right: 5px;}
/**.xy_checkbox:checked:after {content:'';width: 6px;height: 10px;position: absolute;top: 1px;left: 5px;border: 2px solid #fff;border-top: 0;border-left: 0;-webkit-transform: rotate(45deg);transform: rotate(45deg);}**/
.wp-posts-content li{margin-bottom: 0;}
.xy-width{padding:0 30px 30px;}
.wp-posts-content ol>li>span{color: var(--theme-color);}
@media screen and (max-width:500px){.xy-width{padding:10px;}.wp-posts-content ol:not(.blocks-gallery-grid){margin:0;}.xy_hide{display:none;}.title-h-center{display:none;}.xy-mask {background-color: rgb(0 0 0 / 5%);}}
@media screen and (min-width:500px){.xy-width-190{width: 190px;}.xy-width-100{width: 100px;}}
</style>
<br>
<main class="container">
<div class="content-wrap">
<div class="content-layout">
<div class="page-cover theme-box radius8 main-shadow">
<img class="fit-cover no-scale lazyloaded" src="https://api.mduge.com/img/imgmn" data-src="cos.vs98k.cn/uploads/2022/11/14/v2-4df3abc448cb4907a20ad8e35fd55f8e_r.jpg">
<div class="absolute xy-mask"></div>
<div class="list-inline box-body abs-center text-center">
<div class="title-h-center">
<span class="xy_content"><h5><font size="6" color="red"> 注</font>意提醒 </h5>
<li class="xy_li">开启外链重定向会判定失败</li>
<li class="xy_li">网站打开时间过长会请求失败</li>
<li class="xy_li">首页未有本站链接会判定失败</li>
<li class="xy_li">如有疑问可找站长或进群</li>
</span>
</div>
</div>
</div>
<?php while (have_posts()) : the_post(); ?>
<!--友情链接字样?php echo zib_get_page_header(); ?-->
<?php
if ($page_links_content_position == 'top') {
echo '<div class="zib-widget">' . zib_page_links() . '</div>';
}?>
<?php echo Links(); ?>
<?php
echo'<div class="box-body notop">
<div class="title-theme">友链申请说明<small class="ml10">请注意查看</small></div>
</div>
<div class="zib-widget xy-width">
<span class="xy_content" style="display: block;">
<h5>申请前 <font size="6" color="red">必</font> 阅读</h5>
<section class="xy_callout wp-posts-content"
style="font-weight:400;padding:0 20px 10px;margin-bottom:15px;border-left-color: #1890ff;">
<h3>申请条件</h3>
<ol>
<li>先确认申请的博客内容符合以下类别,即使未列出的亦可继续申请。<br>
<i class="fa fa-check" aria-hidden="true"></i>
某领域技术性博客<br>
<i class="fa fa-check" aria-hidden="true"></i>
资源下载类博客<br>
<i class="fa fa-check" aria-hidden="true"></i>
论坛,社区或聚合媒体类网站<br>
<i class="fa fa-times" aria-hidden="true"></i>
纯视频站,纯图片站<br>
<i class="fa fa-times" aria-hidden="true"></i>
赌博、发卡、支付类网站<br>
<i class="fa fa-times" aria-hidden="true"></i>
原创少于1篇的博客<br>
<i class="fa fa-times" aria-hidden="true"></i>
没有独立博客服务器的博客(例如搭设在WordPress,blogger,typecho等)
</li>
<li>博客需每月至少有一篇更新博客,或者有经常更新的日常笔记,并且已存在至少<code>20篇</code>博文。</li>
<li>站点需要全站https,也不接受带ip或端口的链接,并且国内无墙。</li>
<li>在小站有效留言至少一条,至少我得熟悉你吧,这样才好申请友链。</li>
<li>博客有RSS2.0地址或atom地址(一般的博客程序都自带,请不要关闭,如果是自制程序没有可忽略)。</li>
<li style="color:red">权重大于3,以上条件皆可无视。</li>
</ol>
<h3>申请过程</h3>
<ol>
<li>申请前请先将本站友链加好。</li>
<li>申请信息真认真写好,请勿乱写。</li>
<li>申请时请写清<code>网站名称</code> <code>网站头像</code> <code>网站介绍</code> <code>网站链接</code></li>
</ol>
<h3>申请后续</h3>
<ol>
<li>如果不符合要求会无视掉申请,<font color="red">一天内都会通过。</font>
</li>
<li>网站修改友链信息请申请页面留言即可,无格式要求。</li>
<li>排名一般来说是有先后顺序的,但是还是要说,排名不分先后。</li>
<li>若发现站点无法访问,将会在一个月后删除。</li>
<li>网站正常访问但是无故下掉链接的,会拉入黑名单,不再接受友链申请。</li>
<li>本站使用
接口检测模式,
设有重定向、访问过慢的网站无法正常识别。</li>
</ol>
</section>
';
if ($page_links_content_s) {
echo '<div class="zib-widget"><article class="article wp-posts-content">先在贵站添加本站友情链接,添加友情链接后请勿删除本站友情链接,否则上方检测不通过将自动下架贵站链接。';
the_content();
echo '</article>';
wp_link_pages(
array(
'before' => '<p class="text-center post-nav-links radius8 padding-6">',
'after' => '</p>',
)
);
echo '</div>';
}
if ($page_links_content_position == 'top') {
echo zib_page_links();
}
if ($page_links_content_position != 'top') {
echo '<div class="zib-widget">' . zib_page_links() . '</div>';
}
?>
<?php ?>
<?php endwhile;?>
<?php
comments_template('/template/comments.php', true);
if ($widgets_register_container && in_array('bottom_content', $widgets_register_container)) {
dynamic_sidebar('page_bottom_content_' . $post_id);
}?>
</div>
</div>
<?php get_sidebar();?>
</main>
<?php
if ($page_links_submit_s) {
$submit_args = array(
'title' => zib_get_post_meta($post_id, 'page_links_submit_title', true),
'dec' => zib_get_post_meta($post_id, 'page_links_submit_dec', true),
'sign' => zib_get_post_meta($post_id, 'page_links_submit_sign_s', true),
'cats' => zib_get_post_meta($post_id, 'page_links_submit_cats', true),
);
echo zib_submit_links_modal($submit_args);
}
if ($widgets_register_container && in_array('bottom_fluid', $widgets_register_container)) {
echo '<div class="container fluid-widget">';
dynamic_sidebar('page_bottom_fluid_' . $post_id);
echo '</div>';
}
get_footer();
?>
下面这个代码直接放入主题根目录的 func.php文件里面,如果没有这个文件 就先建一个,代码里面url API检测接口自行更换,不换也可以,搜索https://www.dh139.cn换成自已的网址
//友情链接开始
/*友情链接检测
*/
function xy_link(){
global $wpdb;
$links = $wpdb->prefix . 'links';
$user_url = !empty($_REQUEST['user_url']) ? $_REQUEST['user_url'] : '';
$xypro_url = esc_url(home_url());
$url = 'https://www.dh139.cn/urlapi.php?myurl=' . urlencode($xypro_url) . '&targeturl=' . urlencode($user_url);
//初始化
$response = wp_remote_get($url, array(
'timeout' => 20,
'sslverify' => false,
));
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
error_log("HTTP request error: " . $error_message);
zib_send_json_error(array('code' => -1, 'msg' => '请求数据错误: ' . $error_message));
return;
}
$http_code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
$deta = date("Y-m-d H:i:s", time()+8*60*60);
if ($body) {
$data = json_decode($body, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log("JSON decode error: " . json_last_error_msg());
zib_send_json_error(array('code' => -1, 'msg' => 'JSON解析错误: ' . json_last_error_msg()));
return;
}
if ($data['code'] == 200 && isset($data['data']['message']) && $data['data']['message'] == '友情链接存在!') {
$link_visible = 'Y';
$msg = '检测友情链接正常!';
} else {
$link_visible = 'N';
$msg = isset($data['data']['message']) ? $data['data']['message'] : '未获得URL相关数据,请重试!';
}
} else {
$link_visible = 'N';
$msg = '请求数据错误';
}
$link_con = array(
'link_visible' => $link_visible,
'link_updated' => $deta,
'link_notes' => $msg,
);
$wpdb->update($links,$link_con,array('link_url'=> $user_url));
zib_send_json_success(array('code' => 0, 'msg' => $msg));
}
add_action('wp_ajax_xy_link', 'xy_link');
function xy_link_jc(){
global $wpdb;
$links = $wpdb->prefix . 'links';
$deta = date("Y-m-d H:i:s", time()+8*60*60);
$link_YN = !empty($_REQUEST['link_id']) ? $_REQUEST['link_id'] : '';
$link_yn = mb_substr($link_YN, 0, 1, 'utf-8');
$link_id = substr_replace($link_YN,"",0,1);
if($link_yn == 'N'){
$link_con = array(
'link_visible' => 'N',
'link_updated' => $deta,
'link_notes' => '请确认您已经添加本站的链接',
);
$wpdb->update($links,$link_con,array('link_id'=> $link_id));
zib_send_json_success(array('code' => -1, 'msg' => '已将链接隐藏'));
}elseif($link_yn == 'Y'){
$link_con = array(
'link_visible' => 'Y',
'link_updated' => $deta,
'link_notes' => '检测友情链接正常!',
);
$wpdb->update($links,$link_con,array('link_id'=> $link_id));
zib_send_json_success(array('code' => 0, 'msg' => '已将链接显示'));
}elseif($link_yn == 'D'){
$del = $wpdb->delete( $links, array( 'link_id' => $link_id ) );
if($del){
zib_send_json_success(array('code' => 0, 'msg' => '删除成功'));
}
}
}
add_action('wp_ajax_xy_link_jc', 'xy_link_jc');
function Links(){
global $wpdb;
$links = $wpdb->prefix . 'links';
$links_count = $wpdb->get_var( "SELECT COUNT(`link_id`) FROM {$links}" );
if(get_current_user_id() == 1){
$gl = true;
$gl_td = '<th align="center" class="xy-width-100 xy_hide">管理</th>';
}
//<span class="but jb-pink inspect" style="float: right;font-size: 12px;">一键检测</span>
$html = '
<div class="zib-widget">
<h2>友情链接检测
</h2>
<div class="xypro_describe">
<p class="xy_height_hide_p2 xy_display_btn">查看更多友链 <i class="fa fa-angle-down ml6 xy-more-btn"></i></p>
<p class="xy_height_hide_p"></p>
<div class="xypro_describe_title">
检测列表('.$links_count.'条友链)
</div>
<div id="xy_hide" class="xypro_describe_content xy_height_hide">
<table class="yq">
<thead>
<tr>
<th align="center" class="xy-width-190">检测时间</th>
<th align="center">网站名称</th>
<th align="center">下链原因</th>
'.$gl_td.'
</tr>
</thead>';
$html .= ' <tbody class="link-list">';
//获取分页数据 :每页显示的数量 默认为50
$limit = 15;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//计算每一页第一条记录的显示偏移量
//偏移量 = (页码 -1) \* 每页的显示数量
$offset = ( $paged - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`link_id`) FROM $links" );
$pages = ceil( $total / $limit );
//调用
$link = $wpdb->get_results("SELECT * FROM $links WHERE link_id ORDER BY link_id desc LIMIT {$limit} OFFSET {$offset}");
foreach ($link as $k => $v){
$name = $v->link_name;
$btn = '<a href="javascript:;" class="but jb-pink testing" style="float:right;font-size:12px" id="'.$v->link_url.'">检测</a>';
$btn = get_current_user_id() == 1 ? $btn : '';
if($v->link_notes == '检测友情链接正常!'){
$msg_btn = 'color: green;';
}else{
$msg_btn = 'color: red;';
}
if($gl){
$gl_tr_td = '<td class="xy_hide">
<a href="javascript:;" class="admin-btn">管理</a>
<ul class="admin-guanli">
<li><a class="link_JC" href="javascript:;" id="Y'.$v->link_id.'">显示</a></li>
<li><a class="link_JC" href="javascript:;" id="N'.$v->link_id.'">隐藏</a></li>
<li><a class="link_JC" href="javascript:;" id="D'.$v->link_id.'">删除</a></li>
</ul>
</td>';
}
if($v->link_notes == '检测友情链接正常!'){
$title = '检测友情链接正常';
$name = '<a href="'.$v->link_url.'" target="_blank" data-toggle="tooltip" data-original-title="'.$v->link_description.'">'.$name.'</a>';
}elseif($v->link_notes == '未获得URL相关数据,请重试!'){
$title = '请检查网站是否开了重定向';
}elseif($v->link_notes == '请确认您已经添加本站的链接'){
$title = '请检查该链接是否做了本站友链';
}elseif(!$v->link_notes){
$title = '该网站站长还未检测';
}else{
$title = '检测网站访问时间过长';
}
$link_notes = $v->link_notes ? $v->link_notes : '该网站站长还未检测';
$html .= '<tr class="yq_link">
<td>'.$v->link_updated.'</td>
<td>'.$name.'</td>
<td style="'.$msg_btn.'"><span data-toggle="tooltip" data-original-title="'.$title.'">'.$link_notes.'</span><span class="xy_hide">'.$btn.'</span></td>
'.$gl_tr_td.'
</tr>';
}
$html .= '<script>
var clicktype = true;
$(".link_JC").on("click",function(e){
if(confirm(\'是否进入下一步操作?\')) {
if(clicktype == false){return false};
clicktype = false;
var link_id = $(this).attr("id");
$.ajax({
type:"POST",
url:"'.admin_url('admin-ajax.php').'",
data:{
"action":"xy_link_jc",
"link_id":link_id,
},
cache:false,
dataType:"json",
success:function(data){
if(data.code == 0){
notyf(data.msg,"success");
}else{
notyf(data.msg,"warning");
}
clicktype = true;
},
error:function(data){
notyf("请求数据错误","warning");
clicktype = true;
}
});
}
});
</script>';
$html .= '<script>
var clicktype = true;
$(".testing").on("click",function(e){
if(clicktype == false){return false};
clicktype = false;
var link_url = $(this).attr("id");
notyf("检测中请稍等...","load", "2");
var text = "<i class=loading mr6></i> 检测中";
$(this).attr("disabled",true);
$(this).text("");
$(this).append(text);
$(this).addClass("jc-load");
$.ajax({
type:"POST",
url:"'.admin_url('admin-ajax.php').'",
data:{
"action":"xy_link",
"user_url":link_url,
},
cache:false,
dataType:"json",
success:function(data){
if(data.code == 0){
notyf(data.msg,"success");
}else{
notyf(data.msg,"warning");
}
clicktype = true;
$(".jc-load").text("");
$(".jc-load").append("检测");
$(".jc-load").attr("disabled",false);
// link_url.removeClass("jc-load");
},
error:function(data){
notyf("请求数据错误","warning");
clicktype = true;
$(".jc-load").text("");
$(".jc-load").append("检测");
$(".jc-load").attr("disabled",false);
// link_url.removeClass("jc-load");
}
});
})
</script>';
$html .= '<script>
$(document).on("click",".xy_display_btn",function(){
$(".xy_display_btn").remove();
$(".xy_height_hide_p").remove();
$("#xy_hide").removeClass("xy_height_hide");
$(".xypro_describe").append("<p class=\'xy_height_hide_p2 xy_hide_btn\'>隐藏友链列表 <i class=\'fa fa-angle-up ml6 xy-more-btn\'></i></p>");
});
$(document).on("click",".xy_hide_btn",function(){
$(".xy_hide_btn").remove();
$("#xy_hide").addClass("xy_height_hide");
$(".xypro_describe").append("<p class=\'xy_height_hide_p2 xy_display_btn\'>查看更多友链 <i class=\'fa fa-angle-down ml6 xy-more-btn\'></i></p><p class=\'xy_height_hide_p\'></p>");
$("body,html").animate({scrollTop:$(".xypro_describe").offset().top},400);
});
</script>';
$html .= '</tbody></table>';
$html .= $link ? xy_pages($pages,$paged) : '<div class="text-center ajax-item "><img style="width:280px;opacity: .7;" src="https://cos.vs98k.cn/uploads/2024/07/03/null.svg"><p style="" class="em09 muted-3-color separator">暂无友链链接</p></div>';
$html .= '</div></div></div>';
return $html;
}
/**
* 数字分页函数
* 因为wordpress默认仅仅提供简单分页
* 所以要实现数字分页,需要自定义函数
*/
function xy_pages($max_page,$paged) {
$html = '';
$html.= '<style>
.pagination{margin:30px 0;padding:0 10px;text-align:center;font-size:12px;display:block;border-radius:0}
.excerpts .pagination{margin-bottom: 10px;}
.pagination ul{display:inline-block !important;margin-left:0;margin-bottom:0;padding:0}
.pagination ul > li{display:inline}
.pagination ul > li > a,.pagination ul > li > span{margin:0 2px;padding:6px 12px;background-color:#ddd;color:#666;border-radius:2px;opacity:.88}
.pagination ul > li > a:hover,.pagination ul > li > a:focus{opacity:1}
.pagination ul > .active > a,.pagination ul > .active > span{background-color:#1d1d1d;color:#fff}
.pagination ul > .active > a,.pagination ul > .active > span{cursor:default}
.pagination ul > li > span,.pagination ul > .disabled > span,.pagination ul > .disabled > a,.pagination ul > .disabled > a:hover,.pagination ul > .disabled > a:focus{color:#999999;background-color:transparent;cursor:default}
</style>';
$p = 2;
if ( $max_page == 1 ) {
return;
}
$html.= '<span class="pagination"><ul>';
$paged = !empty( $paged ) ? $paged : 1;
if ( $paged > 1 ) {
$html.= '<li><a href="'.esc_html( get_pagenum_link( 1 ) ).'">首页</a></li>';
}
$html.= '<li class="prev-page">';
$html.= '</li>';
for ( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page ) {
if($i == $paged){
$html.= "<li class=\"active\"><span>{$i}</span></li>";
}else{
$html.= '<li><a href="'.esc_html( get_pagenum_link( $i ) ).'">'. $i .'</a></li>';
}
}
}
$html.= '<li class="next-page">';
$html.= '</li>';
$html.= '<li><a href="'.esc_html( get_pagenum_link( $max_page ) ).'">尾页</a></li>';
//$html.= '<li><span>共 '.$max_page.' 页</span></li>';
$html.= '</ul></span>';
return $html;
}
/*友情链接检测*/
//友情链接结束
下面是API接口代码,创建一个 文件为 urlapi.php 名称的文件放到根目录,将代码放进去
<?php
header('Content-Type: application/json; charset=utf-8');
//花猪资源网 www.dh139.cn
// 检查是否传入了 myurl 和 targeturl 参数
if (!isset($_GET['myurl']) || !isset($_GET['targeturl'])) {
echo json_encode(['code' => 400, 'data' => ['message' => '缺少参数: myurl 或 targeturl']], JSON_UNESCAPED_UNICODE);
exit;
}
$myurl = $_GET['myurl'];
$targeturl = $_GET['targeturl'];
// 检查参数是否为空
if (empty($myurl) || empty($targeturl)) {
echo json_encode(['code' => 400, 'data' => ['message' => '参数 myurl 或 targeturl 不能为空']], JSON_UNESCAPED_UNICODE);
exit;
}
// 模拟友情链接存在的逻辑。你可以根据实际需求替换这个部分。
function check_link($myurl, $targeturl) {
// 示例逻辑:简单检查目标URL页面内容中是否包含来源URL
$html = @file_get_contents($targeturl);
if ($html === FALSE) {
return false;
}
return strpos($html, $myurl) !== false;
}
if (check_link($myurl, $targeturl)) {
echo json_encode([
'code' => 200,
'data' => [
'message' => '友情链接存在!',
'myurl' => $myurl,
'targeturl' => $targeturl,
'title' => '检测成功'
]
], JSON_UNESCAPED_UNICODE);
} else {
echo json_encode([
'code' => 404,
'data' => [
'message' => '友情链接不存在!',
'myurl' => $myurl,
'targeturl' => $targeturl,
'title' => '检测失败'
]
], JSON_UNESCAPED_UNICODE);
}
?>
![图片[2]- 子比主题-友情链接自助检测+api自建(修复版)](https://www.dh139.cn/wp-content/uploads/2025/04/1-28-1024x316.jpg)
感谢您的来访,获取更多精彩文章请收藏本站。

暂无评论内容