为主题增加短代码

很多wordpress主题里都带有短代码功能,如果没有可以使用插件或者自己添加。插件使用很简单,如果自己添加的话要麻烦些。我的主题添加了扒自Mossight的代码,具体操作如下:
第一步,在functions.php中加入
[text]function archives_maxpage(){$count_posts = wp_count_posts();$published_posts = $count_posts->publish;$max_page = ceil( $published_posts/16 );return $max_page;}add_action('media_buttons_context', 'add_my_custom_button');function add_my_custom_button($context) {$img = '<img src="' . get_bloginfo('template_url') . '/images/ddm.png" width="15" height="15" />';$context .='<a href="#" id="ddm-button" title="短代码" class="thickbox">' . $img . '</a>';return $context;}add_action('admin_footer', 'media_upload_for_upyun');function media_upload_for_upyun(){ ?><div id="ddm-lay"></div><div id="ddm-box"><div id="ddm-content" class="cfx"><ul id="ddm-cate"><li><a href="#" class="current">静态面板短代码</a></li><li><a href="#">新版静态面板短代码</a></li><li><a href="#">按钮短代码</a></li><li><a href="#">音乐</a></li><li><a href="#">视频播放短代码</a></li></ul><ul id="ddm-ddm"><li class="cfx current"><p>旧版</p><a href="1">下载面板</a><a href="2">警告面板</a><a href="3">介绍面板</a><a href="4">文本面板</a><a href="5">教程面板</a><a href="6">项目面板</a><a href="7">错误面板</a><a href="8">提问面板</a><a href="9">链接面板</a><a href="10">代码面板</a></li><li class="cfx"><p>新版</p><a href="11">下载面板</a><a href="12">警告面板</a><a href="13">介绍面板</a><a href="14">文本面板</a><a href="15">教程面板</a><a href="16">项目面板</a><a href="17">错误面板</a><a href="18">提问面板</a><a href="19">链接面板</a><a href="20">代码面板</a></li><li class="cfx"><a href="21">下载按钮</a><a href="22">爱心图标</a><a href="23">文本图标</a><a href="24">盒子图标</a><a href="25">搜索图标</a><a href="26">文档图标</a><a href="27">链接图标</a><a href="28">箭头图标</a><a href="29">音乐图标</a></li><li class="cfx"><a href="30">音乐</a><a href="31">音乐(可自动播放)</a></li><li class="cfx"><a href="33">优酷</a><a href="34">土豆</a><a href="35">酷6</a><a href="36">音悦台</a></li></ul><a id="ddm-close" href="#">X</a></div></div><link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie7.css" type="text/css" media="all">;<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.ddm.js"></script><?php }include_once('functions/shortcode.php');[/text]

第二步,上传shortcode.php到functions,shortcode到images
点击下载:[down]shortcodefunctions[/down]

第三步,添加相应的css
[newcode]/*shortcode*/
.toggle_content {
background:#F5F5F5;
color:#515151;
border-left:1px solid #DEDEDE;
border-bottom:1px solid #DEDEDE;
border-right:1px solid #DEDEDE;
overflow:auto;
margin:-3px 0 15px;
padding:5px 15px;
}
.newcontent {
border:1px solid #FFF;
background:#F5F5F5;
color:#515151;
padding:45px 15px 10px;
}
.newdown,.newwarning,.newauthor,.newtext,.newtutorial,.newproject,.newerror,.newquestion,.newlink,.newcode {
border:1px solid #DFDFDF;
margin:20px 0;
}
.newdown h2,.newwarning h2,.newauthor h2,.newtext h2,.newtutorial h2,.newproject h2,.newerror h2,.newquestion h2,.newlink h2,.newcode h2 {
float:left;
text-align:left!important;
width:555px;
height:34px;
color:#666;
font-size:15px;
padding:8px 0 0 52px;
}
.newdown h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat;
}
.newwarning h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -42px;
}
.newauthor h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -84px;
}
.newtext h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -126px;
}
.newtutorial h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -168px;
}
.newproject h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -210px;
}
.newerror h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -252px;
}
.newquestion h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -294px;
}
.newlink h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -336px;
}
.newcode h2 {
background:url(images/shortcode/shortcode.jpg) no-repeat 0 -378px;
}
.codei {
min-height:70px;
margin:20px 0;
}
.box-content {
min-height:95px;
border:1px solid #FFF;
padding:10px 10px 0 105px;
}
.down {
background:url(images/shortcode/download.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.warning {
background:url(images/shortcode/warning.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.panelauthor {
background:url(images/shortcode/author.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.texticon {
background:url(images/shortcode/text.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.tutorial {
background:url(images/shortcode/tutorial.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.project {
background:url(images/shortcode/project.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.error {
background:url(images/shortcode/error.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.question {
background:url(images/shortcode/question.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.blink {
background:url(images/shortcode/blink.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.codee {
background:url(images/shortcode/codee.png) no-repeat scroll 17px 14px #F5F5F5;
border:1px solid #DFDFDF;
color:#515151;
}
.but-down,.but-heart,.but-text,.but-box,.but-search,.but-document,.but-link,.but-next,.but-music {
display:inline-block;
margin:12px 20px 12px 0;
}
.but-down a,.but-heart a,.but-text a,.but-box a,.but-search a,.but-document a,.but-link a,.but-next a,.but-music a {
color:#474747!important;
float:left;
font-size:13px;
height:33px;
padding-right:15px;
text-decoration:none;
text-shadow:1px 1px 1px #FFF!important;
}
.but-down a span,.but-heart a span,.but-text a span,.but-box a span,.but-search a span,.but-document a span,.but-link a span,.but-next a span,.but-music a span {
float:left;
height:33px;
padding-left:40px;
padding-top:5px;
}
.but-down a span {
background:url(images/shortcode/but-down.png) no-repeat scroll 0 0 transparent;
}
.but-down a {
background:url(images/shortcode/but-down.png) no-repeat scroll right -34px transparent;
}
.but-down a:hover span {
background:url(images/shortcode/but-down.png) no-repeat scroll left -68px transparent;
}
.but-down a:hover {
background:url(images/shortcode/but-down.png) no-repeat scroll right -102px transparent;
}
.but-heart a span {
background:url(images/shortcode/but-heart.png) no-repeat scroll 0 0 transparent;
}
.but-heart a {
background:url(images/shortcode/but-heart.png) no-repeat scroll right -34px transparent;
}
.but-heart a:hover span {
background:url(images/shortcode/but-heart.png) no-repeat scroll left -68px transparent;
}
.but-heart a:hover {
background:url(images/shortcode/but-heart.png) no-repeat scroll right -102px transparent;
}
.but-text a span {
background:url(images/shortcode/but-text.png) no-repeat scroll 0 0 transparent;
}
.but-text a {
background:url(images/shortcode/but-text.png) no-repeat scroll right -34px transparent;
}
.but-text a:hover span {
background:url(images/shortcode/but-text.png) no-repeat scroll left -68px transparent;
}
.but-text a:hover {
background:url(images/shortcode/but-text.png) no-repeat scroll right -102px transparent;
}
.but-box a span {
background:url(images/shortcode/but-box.png) no-repeat scroll 0 0 transparent;
}
.but-box a {
background:url(images/shortcode/but-box.png) no-repeat scroll right -34px transparent;
}
.but-box a:hover span {
background:url(images/shortcode/but-box.png) no-repeat scroll left -68px transparent;
}
.but-box a:hover {
background:url(images/shortcode/but-box.png) no-repeat scroll right -102px transparent;
}
.but-search a span {
background:url(images/shortcode/but-search.png) no-repeat scroll 0 0 transparent;
}
.but-search a {
background:url(images/shortcode/but-search.png) no-repeat scroll right -34px transparent;
}
.but-search a:hover span {
background:url(images/shortcode/but-search.png) no-repeat scroll left -68px transparent;
}
.but-search a:hover {
background:url(images/shortcode/but-search.png) no-repeat scroll right -102px transparent;
}
.but-document a span {
background:url(images/shortcode/but-document.png) no-repeat scroll 0 0 transparent;
}
.but-document a {
background:url(images/shortcode/but-document.png) no-repeat scroll right -34px transparent;
}
.but-document a:hover span {
background:url(images/shortcode/but-document.png) no-repeat scroll left -68px transparent;
}
.but-document a:hover {
background:url(images/shortcode/but-document.png) no-repeat scroll right -102px transparent;
}
.but-link a span {
background:url(images/shortcode/but-link.png) no-repeat scroll 0 0 transparent;
}
.but-link a {
background:url(images/shortcode/but-link.png) no-repeat scroll right -34px transparent;
}
.but-link a:hover span {
background:url(images/shortcode/but-link.png) no-repeat scroll left -68px transparent;
}
.but-link a:hover {
background:url(images/shortcode/but-link.png) no-repeat scroll right -102px transparent;
}
.but-next a span {
background:url(images/shortcode/but-next.png) no-repeat scroll 0 0 transparent;
}
.but-next a {
background:url(images/shortcode/but-next.png) no-repeat scroll right -34px transparent;
}
.but-next a:hover span {
background:url(images/shortcode/but-next.png) no-repeat scroll left -68px transparent;
}
.but-next a:hover {
background:url(images/shortcode/but-next.png) no-repeat scroll right -102px transparent;
}
.but-music a span {
background:url(images/shortcode/but-music.png) no-repeat scroll 0 0 transparent;
}
.but-music a {
background:url(images/shortcode/but-music.png) no-repeat scroll right -34px transparent;
}
.but-music a:hover span {
background:url(images/shortcode/but-music.png) no-repeat scroll left -68px transparent;
}
.but-music a:hover {
background:url(images/shortcode/but-music.png) no-repeat scroll right -102px transparent;
}[/newcode]

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: