友情链接

目前不开放公开添加友链, 如果有意向添加友链的请联系我的个人社交账号或是邮箱

我用的主题给的友链卡片不太好用, 于是我自己写了一个, 当时开始写肯定是想怎么省事怎么来, 我的主题给了两种友链卡片短代码, 比较新的那种不好看而且使用的是WP自带的链接,也就是我说我无法选择上什么链接, 我以后需要添加什么链接都必须得是友链, 而且还无法自主排序; 而比较老的方法虽然连用都不能用 ( 代码有点问题 ) 但是起码颜值还行, 而且不基于WP的链接, 定制度很高, 于是我决定对较老的方法进行修改。

老方法根本无法显示的问题我觉得主要来自 shortcode_content_preprocess , 我猜测这个函数处理的时候会直接删除所有的换行, 而老方法分类链接的方法其实基于换行符和管道符, 导致只能显示第一个管道符前的东西, 后面就解析出错了。( 我没看 shortcode_content_preprocess 的代码的, 不要随便相信我🥺)

既然是这样, 我觉得也没必要为这个友链创造一个新的 shortcode_content_preprocess , 干脆换判断方法好了, 我一开始选了 & 还是不行, 估计又触犯到什么保留字符了, 然后我试了空格, 成功了, 只是现在我不能随意使用空格了, 只能用 _ 代替。然后我去一些大佬的网站那里偷了点理解, 用自己贫瘠的 CSS 知识写了个比原先稍微好看的卡片出来。

add_shortcode('sfriendlinks','shortcode_friend_link_simple');
function shortcode_friend_link_simple($attr,$content=""){
	$content = shortcode_content_preprocess($attr, $content);
	$content = trim(strip_tags($content));
	$entries = explode(" " , $content);
	//return $entries[0];

	$shuffle = isset( $attr['shuffle'] ) ? $attr['shuffle'] : 'false';
	if ($shuffle == "true"){
		mt_srand();
		$group_start = 0;
		foreach ($entries as $index => $value){
			$now = explode("|" , $value);
			if ($now[0] == 'category'){
				echo ($index-1).",".$group_start." | ";
				for ($i = $index - 1; $i >= $group_start; $i--){
					echo $i."#";
					$tar = mt_rand($group_start , $i);
					$tmp = $entries[$tar];
					$entries[$tar] = $entries[$i];
					$entries[$i] = $tmp;
				}
				$group_start = $index + 1;
			}
		}
		for ($i = count($entries) - 1; $i >= $group_start; $i--){
			$tar = mt_rand($group_start , $i);
			$tmp = $entries[$tar];
			$entries[$tar] = $entries[$i];
			$entries[$i] = $tmp;
		}
	}

	$row_tag_open = False;
	$out = "<div class='friend-links-simple'>";
	foreach($entries as $index => $value){
		$now = explode("|" , $value);
		if ($now[0] == 'category'){
			if ($row_tag_open == True){
				$row_tag_open = False;
				$out .= "</div>";
			}
			$out .= "<div class='friend-category-title text-black'>" . $now[1] . "</div>";
		}
		if ($now[0] == 'link'){
			if ($row_tag_open == False){
				$row_tag_open = True;
				$out .= "<div class='row'>";
			}
			$out .= "
			<div class='link mb-2 col-lg-4 col-md-6'>
				<a target='_blank' href='" . $now[1] . "'>
				<div class='card shadow-sm'>
					<div class='d-flex'>
						<div class='friend-link-avatar'>
							";
			if (!ctype_space($now[4]) && $now[4] != '' && isset($now[4])){
				$out .= "<img src='" . $now[4] . "' class='icon bg-gradient-secondary rounded-circle text-white' style='pointer-events: none;'>
						</img>";
			}else{
				$out .= "<div class='icon icon-shape bg-gradient-primary rounded-circle text-white'>" . mb_substr($now[2], 0, 1) . "
						</div>";
			}

			$out .= "		
						</div>
						<div class='pl-3'>
							<div class='friend-link-title title text-primary'><span >" . $now[2] . "</span>
						</div>";
			if (!ctype_space($now[3]) && $now[3] != ''  && isset($now[3])){
				$out .= "<p class='friend-link-description'>" . $now[3] . "</p>";
			}else{
				/*$out .= "<p class='friend-link-description'>&nbsp;</p>";*/
			}
			$out .= "
						</div>
					</div>
				</div></a>
			</div>";
		}
	}
	if ($row_tag_open == True){
		$row_tag_open = False;
		$out .= "</div>";
	}
	$out .= "</div>";
	return $out;
}

额外 CSS : ( 因为懒得写进去 )

.post-content .card.shadow-sm{
	background-color: #242526!important;
	box-shadow: 0px 10px 15px -3px rgba(0,0,0,1)!important;
	border-radius: 15px;
	margin-bottom: 20px;
	transition: transform 0.3s ease;
}
.post-content .card.shadow-sm:hover {
    transform: scale(1.05);
}

示例 : ( 用空格符代替换行即可 )

[sfriendlinks] category|Jack的友人们 link|https://i.needwe.top|Logic|梦想的天空无限大|https://cdn.jsdelivr.net/gh/SwedishDoveCooker/ImgBed@main/202405281217293.png link|https://jvavmaster.github.io/onlycpfans/|Jvav_Master|</p><script>alert(1);</script><p>|https://cdn.jsdelivr.net/gh/SwedishDoveCooker/ImgBed@main/202407131137142.png link|https://jokemaker.top/|Joke_Maker(已经似了)|闹笑话的人|https://cdn.jsdelivr.net/gh/SwedishDoveCooker/ImgBed@main/202407111612497.png [/sfriendlinks]

可能用大佬能想到更好的方法, 但是我已经满足了懒得折腾了😋

No comments yet:S

Send your comments here! Edit comments


				
Ciallo~(∠・ω< )⌒☆.
¯\_(ツ)_/¯
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
 ̄﹃ ̄
(/ω\)
→_→
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(ฅ´ω`ฅ)
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
颜文字
tg_emoji
Firefly
鼬子
我有抑郁症