准备做个wordpress的主题,结果看到了如下的语法:
<div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php if ( is_home() && ! is_front_page() ) : ?> <header> <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1> </header> <?php endif; ?> <?php // Start the loop. while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); // End the loop. endwhile; // Previous/next page navigation. the_posts_pagination( array( 'prev_text' => __( 'Previous page', 'twentyfifteen' ), 'next_text' => __( 'Next page', 'twentyfifteen' ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>', ) ); // If no content, include the "No posts found" template. else : get_template_part( 'content', 'none' ); endif; ?> </main><!-- .site-main --> </div><!-- .content-area -->
这才知道php是有不太常用的替代语法的: 据 http://www.jb51.net/article/23252.htm
PHP中那些语法有替代语法?
流程控制(包括if,while,forforeach,switch)这几个语句有替代语法。
替代语法的基本形式:
左花括号({)换成冒号(:),把右花括号(})分别换成 endif;,endwhile;,endfor;,endforeach; 以及 endswitch;
举个例子吧:
复制代码代码如下:
是负数拉
上面的语句等同于
是负数拉
复制代码代码如下:
复制代码代码如下:
复制代码代码如下:
复制代码代码如下:
复制代码代码如下:
switch ($i):
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
default:
echo "i is not equal to 0, 1 or 2";
endswitch;
?>
版权声明:本文为博主原创文章,未经博主允许不得转载。