简单框架。

dev-master 2015-08-17 12:12 UTC

This package is not auto-updated.

Last update: 2024-09-18 10:32:36 UTC


README

将Laravel的强大模板引擎Blade引入WordPress。只需安装即可开始在您的主题中使用blade。

Blade是Laravel(一个由Taylor Otwell开发的非常流行的PHP框架)的模板引擎。此插件将相同的模板引擎引入WordPress。使用模板引擎将使模板文件更加清晰,并加快开发速度。模板文件中仍然可以使用常规的PHP。该插件还添加了WordPress特定的blade片段。查看示例以获取更多信息。

WordPress仓库: Blade

YouTube上的Blade教程: 视频教程

输出/打印

// Normal
<?php echo $foo; ?>

// Blade
{{ $foo }}

帖子数据

// Normal
<?php the_title(); ?>

// Blade
{{ the_title() }}

条件语句

常规

<?php if( has_post_thumbnail() ) : ?>
    <?php the_post_thumbnail() ?>
<?php else: ?>
    <img src="<?php bloginfo( 'stylesheet_directory' ) ?>/images/thumbnail-default.jpg" />
<?php endif; ?>

Blade

@if( has_post_thumbnail() )
    {{ the_post_thumbnail() }}
@else
    <img src="{{ bloginfo( 'stylesheet_directory' ) }}/images/thumbnail-default.jpg" />
@endif

WordPress循环

常规

<ul>
	<?php $query = new WP_Query( array( 'post_type' => 'post' ) ); ?>
	<?php if ( $query->have_posts() ) : ?>
	        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
	        <li><a href="<?php the_permalink() ?>"> <?php the_title() ?> </a></li>
	        <?php endwhile; ?>
	<?php else : ?>
	        <li><?php _e( 'Sorry, no posts matched your criteria.' ) ?></li>
	<?php endif; wp_reset_postdata(); ?>
</ul>

Blade

<ul>
	@wpquery( array( 'post_type' => 'post' ) )
	        <li><a href="{{ the_permalink() }}">{{ the_title() }}</a></li>
	@wpempty
	        <li>{{ __( 'Sorry, no posts matched your criteria.' ) }}</li>
	@wpend
</ul>

高级自定义字段

常规

<ul>
    <?php if( get_field( 'images' ) ): ?>
        <?php while( has_sub_field( 'images' ) ): ?>
            <li><img src="<?php the_sub_field( 'image' ) ?>" /></li>
        <?php endwhile; ?>
    <?php endif; ?>
</ul>

Blade

<ul>
    @acfrepeater('images')
        <li>{{ get_sub_field( 'image' ) }}</li>
    @acfend
</ul>

包含文件

与函数一起包含的文件,例如 the_header(),将不会被Blade编译,但是文件中的PHP代码仍然会执行。要使用Blade包含文件,请使用

@include( 'header' )

注意,您不应输入“ .php”。

布局

master.php

<html>
    <div class="content">
        @yield( 'content' )
    </div>
</html>

page.php

@layout( 'master' )

@section( 'content' )
    <p>Lorem ipsum</p>
@endsection

文档

查看完整的Blade文档以获取更多示例。

贡献

非常欢迎拉取请求。请随意报告错误、错别字、增强功能或您想要添加到插件的功能。