木材中ACF中继器场的随机顺序

时间:2017-08-11 12:33:39

标签: twig advanced-custom-fields timber

我试图在基于Timber / Twig的WordPress主题中以自定义顺序显示高级自定义字段转发器。是否可以安装数组扩展(http://twig-extensions.readthedocs.io/en/latest/array.html)来实现这一目标或如何实现?我此刻完全迷失了,并会对如何解决它的任何想法表示赞赏。

2 个答案:

答案 0 :(得分:1)

我不会使用树枝延伸。

为什么不这样:

$rows = get_field( 'repeater_field' );
if( $rows ) {
    shuffle( $rows );

    foreach( $rows as $row ) {
        // your code
    }
}

答案 1 :(得分:0)

在你的php文件中(index.php,page.php等)

// Create context
$context = Timber::get_context();

// Get Field
$repeat = get_field('my_repeater_field');

// Shuffle it
shuffle($repeat);

// Add it to context
$context['repeat'] = $repeat;

然后像通常那样在你的twig文件中调用它

相关问题