将这个jekyll代码转换为PHP的最有效方法是什么?

时间:2016-09-01 13:42:36

标签: php html css jekyll

将此jekyll代码转换为PHP的最有效方法是什么?

{% for post in site.posts limit: 12 %}
    <a href="{{post.url}}" style="background-image: url(assets/img/posts/thumbnails/{{post.thumbnail}})" class="academic-thumb">
        <div class="academic-meta">
            <div class="name">
                {{post.title}}
            </div>
        </div>
    </a>
{% endfor %}

1 个答案:

答案 0 :(得分:1)

<?php
  foreach ($site->getPosts() as $post) {
    echo '
      <a href="'. $post->getUrl() .'" style="background-image: url(assets/img/posts/thumbnails/'. $post->getThumbnail() .')" class="academic-thumb">
    <div class="academic-meta">
        <div class="name">
            '. $post->getTitle() .'
        </div>
    </div>
        </a>';
  }

这当然只有在$ post对象可用且已收集变量时才有效。

你还应该听@borracciaBlu:首先研究ruby语法和php语法