网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > WordPress
User Name
Password
 
FAQ Members List Calendar Cheap Glasses Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1   IP: 218.2.67.86
Old 2012-07-05, 10:25 PM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default WordPress不同分类使用不同的侧边栏sidebar

WordPress群里有朋友问到如何使不同的页面调用不同的侧边栏,比如首页的侧边栏和分类页的侧边栏不一样,或者分类页的侧边栏和内容页的又不一样,这样的功能我们可以用代码实现,前提就是你的侧边栏不是通过管理控制板后台里面的小工具来生成的,而是在模板文件sidebar.php中代码生成的。只有是代码生成的侧边栏,才能同样用代码来控制不同页面显示不同的侧边栏内容。

下面的代码是我的sidebar.php模板文件里面的部分代码:
Code:
<li><h2>标签云图</h2>
  <div>
  <?php wp_tag_cloud('smallest=8&largest=20&orderby=count&order=DESC&number=30'); ?> 
  </div>
 </li>
Code:
<li><h2>最新文章</h2>
  <?php query_posts('showposts=7&cat=-111'); ?>  
  <ul>  
   <?php while (have_posts()) : the_post(); ?>  
   <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  
   <?php endwhile;?>  
  </ul>
 </li>
假如我们只想让标签云图在首页显示,不在分类栏目下面显示出来,那么我们可以在标签云图的代码前面加上条件控制代码,is_home(),最后的代码如下:
Code:
<?php if(is_home()): ?>
 <li><h2>标签云图</h2>
  <div>
  <?php wp_tag_cloud('smallest=8&largest=20&orderby=count&order=DESC&number=30'); ?> 
  </div>
 </li>
<?php endif; ?>
Code:
<li><h2>最新文章</h2>
  <?php query_posts('showposts=7&cat=-111'); ?>  
  <ul>  
   <?php while (have_posts()) : the_post(); ?>  
   <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  
   <?php endwhile;?>  
  </ul>
 </li>
如首页的侧边栏里面的最新文章调用所有分类的最新文章,而某个分类页面的侧边栏里面的最新文章显示该分类里面的最新文章。这种情况,我们可以通过加入下面的代码来实现:
Code:
<?php if (in_category('111')) : ?>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:23 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.