1.教程简介
我们在使用任一款wordpress主题时,都会有微调主题的想法,用以实现个人的主题特色。本篇教程是针对知更鸟主题cms设置页Tab显示增加选项卡教程,使用其他主题可通过本教程修改文件作为参考。
先附上一张原图,一张修改后的图片,看下效果:
原图
修改后效果
2.修改步骤(修改前请备份源文件)
2.1:(cms-tab.php文件修改)
找到主题文件夹下cms文件夹里面的cms-tab.php文件:
添加以下代码在tab_c整段代码之后。
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_d'); ?></a></span>
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_e'); ?></a></span>
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_f'); ?></a></span>
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_g'); ?></a></span>
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_k'); ?></a></span>
- <span class="tab-hd-con"><a href="javascript:"><?php echo zm_get_option('tab_j'); ?></a></span>
在“ <div class="tab-bd dom-display"> ”内最后的</div>上面加入以下代码
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabw_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('taby_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabm_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabg_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabh_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabx_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- <ul class="tab-bd-con">
- <?php query_posts('showposts='.zm_get_option('tabt_n').'&cat='.zm_get_option('tabz_n')); while (have_posts()) : the_post(); ?>
- <?php the_title( sprintf( '<li class="list-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
2.2(cms-dow-tab.php文件修改)
找到主题文件夹下cms文件夹里面的cms-dow-tab.php文件:
在<div class="img-tab-hd">末尾</div>上面加入以下代码
- <?php if ( zm_get_option('dow_tab_d') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_d'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_e') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_e'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_f') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_f'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_g') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_g'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_k') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_k'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_i') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_i'); ?></a></span><?php } ?>
- <?php if ( zm_get_option('dow_tab_j') == '' ) { ?><?php } else { ?><span class="img-tab-hd-con"><a href="javascript:"><?php echo zm_get_option('dow_tab_j'); ?></a></span><?php } ?>
在<div class="img-tab-bd img-dom-display">末尾的</div>标签上面加入以下代码
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_d_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_d_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_e_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_e_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_f_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_f_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_g_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_g_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_k_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_k_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_i_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_i_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
- <div class="img-tab-bd-con">
- <p class="edd-inf"><?php echo zm_get_option('dow_tab_j_s'); ?></p>
- <?php
- $args = array('tax_query' => array( array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => explode(',',zm_get_option('cms_edd_j_id') ))), 'posts_per_page' => zm_get_option('cms_edd_n'));
- query_posts($args); while ( have_posts() ) : the_post();
- ?>
- <article id="post-<?php the_ID(); ?>" class="w4 x4">
- <div class="picture">
- <figure class="picture-img">
- <?php tao_thumbnail(); ?>
- </figure>
- <?php the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
- <div class="img-tab-meta">
- <div class="img-cat">分类:<?php echo get_the_term_list($post->ID, 'download_category', '', ', ', ''); ?></div>
- <div class="clear"></div>
- </div>
- </div>
- </article>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- <div class="clear"></div>
- </div>
2.3(options.php文件修改)
搜索id' => 'tab_c在 “ ); ”下面添加以下代码
- $options[] = array(
- 'name' => 'Tab“特色文章1”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_d',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabw_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章2”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_e',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'taby_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章3”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_f',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabm_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章4”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_g',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabg_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章5”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_k',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabh_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章6”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_i',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabx_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
- $options[] = array(
- 'name' => 'Tab“特色文章7”设置',
- 'desc' => '自定义文字',
- 'id' => 'tab_j',
- 'std' => '分类文章',
- 'type' => 'text'
- );
- if ( $options_categories ) {
- $options[] = array(
- 'name' => '',
- 'desc' => '选择一个分类',
- 'id' => 'tabz_n',
- 'type' => 'select',
- 'options' => $options_categories);
- }
2.4(修改style.css文件)
在style.css文件中搜索 tab-product ,修改width值,直至页面美观即可。(使用firebug在网页中调整好以后再行修改style.css中width值。)
将修改后的文件上传到相应的位置替换原文件。
3.注意事项
如启用静态缓存插件,请清理缓存。至此便能看到和本站一样的tab选项卡效果了。
如需,修改tab选项卡数量,可参照以上修改文件对代码进行删减或增加。
继续阅读
评论