-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharticle.php
More file actions
74 lines (71 loc) · 2.96 KB
/
article.php
File metadata and controls
74 lines (71 loc) · 2.96 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
64
65
66
67
68
69
70
71
72
73
74
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<article class="post">
<div class="author-avatar">
<img
alt="<?php $this->author() ?>"
loading="lazy"
fetchpriority="low"
src="<?php echo getGravatarUrl($this->author->mail); ?>">
</div>
<div class="content">
<div class="post-info">
<div class="author-name">
<?php $this->author(); ?>
<?php // 显示广告标识
$isAdvertise = getArticleFieldsByCid($this->cid, 'isAdvertise');
if (!empty($isAdvertise) && ($isAdvertise[0]['int_value'] == 1 || $isAdvertise[0]['str_value'] == '1')):
?>
<div class="author-badge">广告</div>
<?php endif; ?>
</div>
<div class="post-rank">
<?php if ($this->is('post')):
$db = Typecho\Db::get();
$currentPostId = $this->cid;
$row = $db->fetchRow($db->select('COUNT(*) AS rank')
->from('table.contents')
->where('type = ?', 'post')
->where('status = ?', 'publish')
->where('created <= ?', $this->created));
$rank = $row['rank'];
echo " #{$rank}";
endif; ?>
</div>
</div>
<div class="text">
<?php if ($this->is('single')) : ?>
<?php $content = $this->content;
$content = addAttributesForLinksAndImgs($content);
echo $content; ?>
<?php else: ?>
<?php echo smartExcerpt($this, 140, ''); ?>
<p class="more"><a href="<?php $this->permalink(); ?>" title="<?php $this->title(); ?>">…全文</a></p>
<?php endif; ?>
</div>
<div class="post-meta">
<div class="post-position">
<?php if (!$this->is('index')):
$position = $this->fields->position;
$positionUrl = $this->fields->positionUrl;
?>
<?php
// 只有当 position 有值时才显示内容
if (!empty($position)) {
echo '📍 ';
// 如果有 URL 就显示为链接,否则只显示文本
if (!empty($positionUrl)) {
echo '<a href="' . htmlspecialchars($positionUrl) . '" target="_blank" rel="noopener noreferrer">'
. htmlspecialchars($position) . '</a>';
} else {
echo htmlspecialchars($position);
}
}
?>
<?php endif; ?>
</div>
<div class="date">
<?php echo $this->is('page') ? "更新于 " . date('Y年m月d日', $this->modified) : $this->date('Y年m月d日'); ?>
</div>
</div>
</div>
</article>