badcow/ink

此包已被弃用且不再维护。未建议替代包。
此包最新版本(dev-master)无可用许可信息。

一个由Twig驱动的WordPress模板构建器。

dev-master 2013-03-18 04:33 UTC

This package is auto-updated.

Last update: 2022-02-01 12:23:22 UTC


README

#Ink WordPress Starter Theme

##什么是Ink? Ink是一个WordPress入门主题,利用Twig模板引擎的力量来构建可读的WordPress模板。

##为什么选择Ink? 首先,也是最重要的,PHP不是模板引擎! 如果您不同意,请在争论之前先阅读这篇文章

"如果你认为PHP仍然是模板语言,你能给我一个最近的语言变化,这个变化增强了PHP作为模板语言的能力吗?我想不出来。"

PHP是一种动态语言,它最初的生命起源于作为模板引擎,但已发展成为一个强大、面向社区的编程语言。PHP不再是模板语言。Smarty、Django、HAML和Twig模板语言。

##如果你决定使用Ink,你不会局限于Twig。这绝不是传统WordPress模板的全面替代品。如果Ink(目前)做不到PHP能做到的事情,你仍然可以使用常规模板文件。

##安装Ink 获取Composer composer.phar install badcow/ink

##比较Twig和PHP以下我们将比较两个文件,它们都实现了相同的功能;它们都渲染一个页面并列出其他页面。第一个例子使用Twig,第二个使用PHP。

###Twig语法

{% extends 'base.html.twig' %}

{% block content %}
<section>
    <h1>{{ post.title }}</h1>
    <em>{{ post.date.format('d/m/Y') }}</em><br />
    {{ post.content }}

    <h1>List of posts</h1>

    {% set posts = postQuery.getPosts('post_type=page') %}

    {%for posty in posts %}
        <h2>{{posty.title}}</h2>
        {{posty.content | raw}}
        <hr />
    {% else %}
        <em>There are no posts to be displayed, sorry.</em>
    {% endfor %}

</section>
{% endblock %}

###PHP语法

<?php get_header(); ?>

<section>
    <h1><?php the_title(); ?></h1>

    <?php the_date('d/m/Y', '<em>', '</em>'); ?><br />

    <?php the_content(); ?>

    <h1>List of posts</h1>

    <?php
        $posts = new WP_Query('post_type=page');
        if($posts->have_posts()):
            while($posts->have_posts()): $posts->the_post();
    ?>

                <h2><?php the_title(); ?></h2>
                <?php the_content(); ?>
                <hr />
            <?php endwhile; ?>
        <?php else: ?>
            <em>There are no posts to be displayed, sorry.</em>
        <?php endif; ?>

</section>

<?php get_footer(); ?>

Twig的优势在于其语法更加流畅,更接近HTML而不是PHP。在PHP模板中使用,跟踪所有的循环开始和结束将变得非常困难。