-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinks.php
More file actions
63 lines (59 loc) · 2.48 KB
/
links.php
File metadata and controls
63 lines (59 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* 友链页面模板
*
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
?>
<?php $this->need('header.php'); ?>
<main>
<?php $this->need('article.php'); ?>
<?php
// 友链展示区域
if (isset($this->fields->links)) {
// 处理转义字符
$linksJson = stripslashes($this->fields->links);
$links = json_decode($linksJson, true);
if (json_last_error() === JSON_ERROR_NONE && is_array($links)) : ?>
<?php foreach ($links as $link) : ?>
<article class="post">
<div class="author-avatar">
<a href="<?= htmlspecialchars($link['url']) ?>" target="_blank" rel="noopener noreferrer">
<img
src="<?= htmlspecialchars($link['img']) ?>"
alt="<?= htmlspecialchars($link['title']) ?>"
class="friend-avatar"
loading="lazy">
</a>
</div>
<div class="content">
<div class="author-name">
<a href="<?= htmlspecialchars($link['url']) ?>" target="_blank" rel="noopener noreferrer">
<?= htmlspecialchars($link['title']) ?>
</a>
</div>
<div class="text">
<p><?= !empty($link['description']) ? htmlspecialchars($link['description']) : '' ?></p>
<div class="post-meta">
<div class="post-position">
<span><?= !empty($link['position']) ? htmlspecialchars($link['position']) : '' ?></span>
</div>
<div class="date"><?= !empty($link['date']) ? htmlspecialchars($link['date']) : '' ?></div>
</div>
</div>
</div>
</article>
<?php endforeach; ?>
<?php else :
// 调试用:显示原始JSON
?>
<p class="alert">友链数据格式错误,请检查JSON格式</p>
<pre><?= htmlspecialchars($linksJson) ?></pre>
<?php endif;
} else { ?>
<p class="alert">暂无友链数据</p>
<?php } ?>
<?php $this->need('comments.php'); ?>
</main>
<?php $this->need('footer.php'); ?>