Skip to content

Commit

Permalink
✨ 优化短代码及获取封面图
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Oct 13, 2022
1 parent d7d2a76 commit 041d877
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function pk_the_author_class_out($count)
return '<span class="t-sm c-sub"><i class="fa-regular fa-gem mr-1"></i>' . __('评论达人', PUOCK) . ' LV.' . $level . '</span>';
}

function pk_the_author_class($echo = true, $in_comment = null){
function pk_the_author_class($echo = true, $in_comment = null)
{
global $wpdb, $comment;
if (!$comment) {
$comment = $in_comment;
Expand Down Expand Up @@ -290,9 +291,13 @@ function smilies_custom_button($context)
</a><div id="insert-smiley-wrap" class="pk-media-wrap" style="display: none">' . get_wpsmiliestrans() . '</div>';
}

function get_post_images($post_id = null)
function get_post_images($_post = null)
{
global $post;
if($_post != null){
$post = $_post;
}
$post_id = $post->ID;
// 如果有封面图取封面图
if (has_post_thumbnail()) {
$res = get_the_post_thumbnail_url($post, 'large');
Expand Down Expand Up @@ -400,7 +405,7 @@ function pk_breadcrumbs()
$tag_name = single_tag_title('', false);
$out .= '<li class="breadcrumb-item active " aria-current="page">' . __('标签', PUOCK) . '</li>';
$out .= '<li class="breadcrumb-item active " aria-current="page">' . ($tag_name) . '</li>';
} else if (isset($other_page_title)) {
} else if (isset($other_page_title)) {
$out .= '<li class="breadcrumb-item active " aria-current="page">' . $other_page_title . '</li>';
} else if (is_404()) {
$out .= '<li class="breadcrumb-item active " aria-current="page">' . __('你访问的资源不存在', PUOCK) . '</li>';
Expand Down Expand Up @@ -449,8 +454,8 @@ function content_img_add_alt_title($content)
if (!is_null($images)) {
$title = @$post->post_title;
foreach ($images[1] as $index => $value) {
$new_img = str_replace('<img', '<img title="'. $title . '"
alt="' . $title .'"', $images[0][$index]);
$new_img = str_replace('<img', '<img title="' . $title . '"
alt="' . $title . '"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
Expand Down
6 changes: 3 additions & 3 deletions inc/fun/short-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ function pk_password_read($attr, $content = null)
if (trim($desc) == "") {
$desc = "此处含有隐藏内容,需要正确输入密码后可见!";
}
$out .= '<div class="p-block">' . sc_tips_primary(null, "<i class='fa-regular fa-eye'></i>&nbsp;{$desc}") . '
$out .= '<div class="p-block pk-sc-password-red">' . sc_tips_primary(null, "<i class='fa-regular fa-eye'></i>&nbsp;{$desc}") . '
' . $error . '<form action="' . get_permalink() . '" method="post">
<div class="row">
<div class="col-8 col-md-10">
<input type="password" placeholder="请输入密码" required class="form-control form-control-sm" name="pass">
<input type="password" placeholder="请输入密码" required class="form-control form-control-sm" name="pass"/>
</div>
<div class="col-4 col-md-2 pl-0">
<button class="btn btn-sm btn-primary w-100">立即查看</button>
Expand All @@ -309,7 +309,7 @@ function pk_sc_collapse($attr, $content = null)
extract(shortcode_atts(array(
'title' => null,
), $attr));
$out = '<div><a class="btn btn-primary btn-sm" data-toggle="collapse" href="#' . $scId . '" role="button"
$out = '<div class="pk-sc-collapse"><a class="btn btn-primary btn-sm" data-toggle="collapse" href="#' . $scId . '" role="button"
aria-expanded="false" aria-controls="' . $scId . '"><i class="fa fa-angle-up"></i>&nbsp;' . $title . '</a></div>';
$out .= '<div class="collapse" id="' . $scId . '">' . $content . '</div>';
return $out;
Expand Down

0 comments on commit 041d877

Please sign in to comment.