【问题标题】:What is the most efficient way to convert this jekyll code to PHP? [closed]将此 jekyll 代码转换为 PHP 的最有效方法是什么? [关闭]
【发布时间】:2016-09-01 13:42:36
【问题描述】:

将此 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 %}

【问题讨论】:

  • jekyll 是用 ruby​​ 编写的。所以问题是如何将 ruby​​ 转换为 php?所以先学习 ruby​​ 的语法,然后再学习 php 的...
  • Jekyll 是用 ruby​​ 编写的,但这不是 ruby​​:这是液体语法

标签: php html css jekyll


【解决方案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 语法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多