修改WordPress主题文件(3)

制作sidebar.php

主题目录下创建sidebar.php文件,从index.php中提取代码:

    <!-- Column 2 / Sidebar -->
    <div class="grid_4">
        <h4>Catagories</h4>
        <ul class="sidebar">
            <li><a href="">So who are we?</a></li>
            <li><a href="">Philosophy</a></li>
            <li><a href="">History</a></li>
            <li><a href="">Jobs</a></li>
            <li><a href="">Staff</a></li>
            <li><a href="">Clients</a></li>
        </ul>
        <h4>Archives</h4>
        <ul class="sidebar">
            <li><a href="">January 2010</a></li>
            <li><a href="">December 2009</a></li>
            <li><a href="">Novemeber 2009</a></li>
            <li><a href="">October 2009</a></li>
            <li><a href="">September 2009</a></li>
            <li><a href="">August 2009</a></li>
        </ul>
    </div>
    <div class="hr grid_12 clearfix">&nbsp;</div>

放到sidebar.php中,将index.php、archive.php、page.php和single.php中相关代码删掉,改成:

<?php get_sidebar();?>

对slidebar.php调整,删掉其中所有代码,改成:

    <!-- Column 2 / Sidebar -->
    <div class="grid_4">
        
    <?php if !function_exists('dynamic_sidebar'
                        || !dynamic_sidebar('First_sidebar'?>
        <h4>分类目录</h4>
        <ul>
            <?php wp_list_categories('depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_of=0')?>
        </ul>
    <?php endif?>
        
    <?php if !function_exists('dynamic_sidebar'
                            || !dynamic_sidebar('Second_sidebar'?>        
        <h4>最新文章</h4>
        <ul>
            <?php
                $posts = get_posts('numberposts=6&orderby=post_date');
                foreach($posts as $post{
                    setup_postdata($post);
                    echo '<li><a href="' . get_permalink('">' . get_the_title('</a></li>';
                }
                $post $posts[0];
            ?>
        </ul>
    <?php endif?>
    
    <?php if !function_exists('dynamic_sidebar'
                            || !dynamic_sidebar('Third_sidebar'?> 
        <h4>标签云</h4>
        <p><?php wp_tag_cloud('smallest=8&largest=22')?></p>
    <?php endif?>
        
    <?php if !function_exists('dynamic_sidebar'
                        || !dynamic_sidebar('Fourth_sidebar'?>                    
        <h4>文章存档</h4>
        <ul>
            <?php wp_get_archives('limit=10')?>
        </ul>
    <?php endif?>
    
    </div>
    <div class="hr grid_12 clearfix">&nbsp;</div>

在wp后台——外观——小工具可以正常的拖动小工具到侧边栏。

 

转载于:https://www.cnblogs.com/Archerus/p/5012770.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值