zoukankan      html  css  js  c++  java
  • wordpress模板中用到的条件判断语句例1

    wordpress的模板对于不懂一点程序代码的人来说还是有点难度的,功能强的wordpress模板经常用到一个语句就是条件判断语句,条件判断语句其实结构很简单,但是如果是多重嵌套语句就有点让人晕了。下面是我在利得丰网站的模板中用到的一段代码,功能很简单,就是实现只有在首页时才显示友情链接:

    <?php if (get_option('widget_center_bottom_left_right_active', 'on') == "on") { ?>
    
    				<div class="footer_widgetcenter_left">				
    				<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Footer Widget Bottom-Left')) {} else { ?>
    				<?php wp_reset_query(); if ( is_home() ) { ?> 
    <div class="footer_links">
    <?php wp_list_bookmarks('title_before=<h3>&title_after=</h3>&category_before=&category_after='); ?>
    </div>
    <?php } else {?>
    					<h3><?php echo get_option("widget_center_bottom_left", "Recent Comments"); ?></h3>					
    
    					<div class="footer_comments">
    
    						<ul>						
    
    						<?php 
    
    						wp_reset_query();						
    
    						$comments = get_comments('post_id=0&number=4&status=approve');
    
    						  foreach($comments as $comm) :						 
    
    							echo "<li><a href=\"". $comm->comment_author_url."\" target=\"_blank\">".($comm->comment_author)."</a> on <a href=\"".get_permalink($comm->comment_post_ID)."#comment-".$comm->comment_ID."\">".get_the_title($comm->comment_post_ID)."</a></li>";
    						endforeach;
    
    						?>						
    
    						</ul>
    
    					</div>
    					
    <?php }  ?>
    				<?php }  ?>
    
    				</div>
    

      

    这个语句意思是这样的

    1、最外层

    最外层那个条件判断语句是判断“中部左侧模块有没有打开”,如果打开,就调用该模块的内容。后面所有语句都是嵌套在这个判断语句中的

    1.1第二层

    接上面,如果“中部左侧模块打开”,那么再判断该模块有没有“小工具”,如果有就调用小工具的内容,如果没有就执行下一个条件判断语句:

    1.1.1第三层

    判断是不是在首页,如果是在首页,那么就调用“友情链接”,否则就调用“评论留言”。我没学过php,所以也不懂php语法,最开始把我弄得晕头转向,调试了很久才调试出来。其实最关键点在于两点,一是php语法要正确,另外就是逻辑清晰。

    特记录次,以便以后温习!

  • 相关阅读:
    Windows系统环境变量path优先级测试报告
    URI和URL的区别
    智能引导式报错(Class file name must end with .class)
    【Algorithm】冒泡排序
    【C语言】练习2-9
    【C语言】练习2-8
    【C语言】练习2-1
    【C语言】练习1-23
    【C语言】练习1-22
    【C语言】练习1-21
  • 原文地址:https://www.cnblogs.com/akilis/p/2220789.html
Copyright © 2011-2022 走看看