Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

Commit

Permalink
feature(single/page): add shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
TigerBeanst committed Nov 25, 2019
1 parent d5c8309 commit 2bbf9c2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
10 changes: 5 additions & 5 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
load_template($optionsfile);
add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
include('optionjs.php');
include('shortcode.php');

//邮件通知 by Qiqiboy
function comment_mail_notify($comment_id)
Expand Down Expand Up @@ -228,6 +229,7 @@ function clear_db_cache_archives_list()

add_action('save_post', 'clear_db_cache_archives_list'); // 新发表文章/修改文章时


//文章目录TOC
function article_toc($content)
{
Expand All @@ -237,7 +239,6 @@ function article_toc($content)
* 博客:https://jakting.com/
* 修改时间:2019年10月15日
*/

$reg_title = '/<h(.*?)>(.*?)<\/h.*?>/';
$content_toc = "<ul class=\"toc_list\">";
$title_1 = 0;
Expand All @@ -249,7 +250,8 @@ function article_toc($content)
if ($count == 0) {
//没有
$flag = false;
$return = array(null, null,$flag);
$content = tm_shortcode($content);
$return = array($content, null,$flag);
} else {
//有
function str_replace_limit($search, $replace, $subject, $limit = 1)
Expand Down Expand Up @@ -300,8 +302,7 @@ function str_replace_limit($search, $replace, $subject, $limit = 1)
if ($title_3 != 0) $content_toc .= "</ul></li>";
if ($title_2 != 0) $content_toc .= "</ul></li>";
$content_toc .= "</ul>";
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = tm_shortcode($content);
$flag = true;
//修改文章内部链接完成
$return = array($content, $content_toc,$flag);
Expand Down Expand Up @@ -386,7 +387,6 @@ function TM_GetUserAgent($ua)
}
return $os . " | " . $br;
}

//自定义评论列表模板,来自 https://dedewp.com/17366.html
function zmblog_comment($comment, $args, $depth)
{
Expand Down
2 changes: 1 addition & 1 deletion page.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class="mdui-text-color-white tm-index-single-title"><?php the_title(); ?></span>
</div>
<div class="mdui-card-actions mdui-color-white">
<div class="mdui-typo mdui-typo-subheading mdui-m-a-2 mdui-text-color-grey-600">
<p><?php the_content(); ?></p>
<p><?php echo tm_shortcode(get_the_content(null, false)); ?></p>
<blockquote class="tm-single-end-blockquote">
<p><b>本文采用 <a rel="nofollow noopener" href="https://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC BY-NC-SA 3.0</a> 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。</b></p>
<p><b>本文链接:</b><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></p>
Expand Down
63 changes: 63 additions & 0 deletions shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
//MDUI短代码
function tm_shortcode($content)
{
//可扩展面板
$content = str_replace(
array('[br]', '[panel]', '[/panel]', '[panel-title]', '[panel-title-open]', '[/panel-title]', '[panel-content]', '[/panel-content]'),
array(
'<br>',
'<div class="mdui-panel mdui-panel-gapless" mdui-panel="{accordion: true}">',
'</div><br>',
'<div class="mdui-panel-item"><div class="mdui-panel-item-header">',
'<div class="mdui-panel-item mdui-panel-item-open"><div class="mdui-panel-item-header">',
'</div>',
'<div class="mdui-panel-item-body"><p>',
'</p></div></div>',
),
$content);

//按钮
$content = str_replace(
array('[btn]', '[btn-flat]','[btn-white]','[btn-white-flat]', '[/btn]', '[btn-url]', '[/btn-url]', '[btn-url-new]','[/btn-url-new]'),
array(
'<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-grey-700" ',
'<button class="mdui-btn mdui-ripple mdui-color-grey-700" ',
'<button class="mdui-btn mdui-btn-raised mdui-ripple" ',
'<button class="mdui-btn mdui-ripple" ',
'</button>',
"onclick='window.location.href=\"",
"\"'>",
"onclick='window.open(\"",
"\")'>",
),
$content);

//复选
$content = str_replace(
array('[check]','[uncheck]','[/check]'),
array(
'<label class="mdui-checkbox"><input type="checkbox" disabled checked/><i class="mdui-checkbox-icon"></i>',
'<label class="mdui-checkbox"><input type="checkbox" disabled/><i class="mdui-checkbox-icon"></i>',
'</label>',
),
$content);

return $content;
}

function panel_function()
{
return '<div class="mdui-panel mdui-panel-gapless" mdui-panel="{accordion: true}">';
}

function panel_close_function()
{
return '<div class="mdui-panel mdui-panel-gapless" mdui-panel="{accordion: true}">';
}

add_shortcode('panel', 'panel_function');
add_shortcode('panel-s', 'panel_function');
add_shortcode('/panel', 'panel_close_function');


2 changes: 1 addition & 1 deletion single.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class="mdui-text-color-white tm-index-single-title"><?php the_title(); ?></span>
<div class="mdui-card-actions mdui-color-white">
<div class="mdui-typo mdui-typo-subheading mdui-m-a-4 mdui-text-color-grey-600">
<p><?php $content = article_toc(get_the_content(null, false));
echo $content[0]; ?></p>
echo $content[0];?></p>
<?php if(!$content[2]){//没有目录?>
<button id="toTop"
class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-grey-700" mdui-fab="{trigger: 'click'}"><i
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ body {
}

.tm-mobile {
padding-top: 40px;
padding-top: 56px;
}


Expand Down

0 comments on commit 2bbf9c2

Please sign in to comment.