其他功能性代码

Wordpress

1. tag标签内链

自动为文章添加tag标签内链,将代码放入主题functions.php文件内

/* 自动为文章内的标签添加内链开始 */
$match_num_from = 1; //一篇文章中同一个标签少于几次不自动链接
$match_num_to = 1; //一篇文章中同一个标签最多自动链接几次
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = "";
$limit = rand($match_num_from,$match_num_to);
$content = preg_replace( '|(]+>)(.*)('.$ex_word.')(.*)(]*>)|U'.$case, '$1$2$4$5', $content);
$content = preg_replace( '|()|U'.$case, '$1$2$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(]*?)>)|([^>]*?))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tag_link',1);
/* 自动为文章内的标签添加内链结束 */

2. 短代码

创建短代码并在编辑器添加快捷按钮,将代码放入主题functions.php文件内

// 添加短代码
function duandaima() {
?>
内容
<?php
}

add_shortcode('duanm','duandaima'); // 短代码用[][/]使用

// 编辑器添加短代码按钮
function duandaimaanniu() {
?>
<script type="text/javascript">
QTags.addButton( 'duandaima', '卡片按钮名称', '4984651','' ); // 添加短代码按钮
</script>
<?php
}
add_action('admin_print_footer_scripts', 'duandaimaanniu' ); // 编辑框添加

2. HTML

1. 代码段折叠

点击时的区域标题:点击查看详细内容

- 测试 测试测试

title,value,callBack可以缺省
  • details:折叠语法标签
  • summary:折叠语法展示的摘要
  • pre:以原有格式显示元素内的文字是已经格式化的文本
  • code:指定代码范例
  • blockcode:表示程序的代码块

3. CSS

4. JS

5. PHP

6. Markdown

表格

# 语法
| Align `center` |
| :-------------: |
| 标题->连字符(---) |
| 分隔每列->管道(|) |
| 对齐->冒号(:) |
| 强调->反引号(`) |


# 对齐方法
| Align `left` | center `align` | Align `right` |
|:------------- | :----------: | ------------: |
| `left`-aligned | `centered` | `right`-aligned |
| `左`对齐 | 中对齐 | 右对齐 |

其他