WordPress-如何在循环中将变量与木材(细枝)连接起来

WordPress-如何在循环中将变量与木材(细枝)连接起来,wordpress,twig,timber,Wordpress,Twig,Timber,我在WordPress中使用木材(细枝) 我正在尝试创建一个标签系统,其中包含两个不同的帖子列表。我正在尝试获取每个列表的帖子数量(自定义帖子类型视频和自定义帖子类型播客) 示例:视频(3)/podcast(12) 我创建了一个循环来获取每个自定义帖子类型(视频和播客)的帖子列表 category.php 类别.细枝 如何将我的数组中的值$posts\u types\u selected与posts\u连接起来 更新 我在这里尝试了解决方案: 我得到:视频(posts\u videos)/pod

我在WordPress中使用木材(细枝)

我正在尝试创建一个标签系统,其中包含两个不同的帖子列表。我正在尝试获取每个列表的帖子数量(自定义帖子类型视频和自定义帖子类型播客)

示例:视频(3)/podcast(12)

我创建了一个循环来获取每个自定义帖子类型(视频和播客)的帖子列表

category.php 类别.细枝 如何将我的数组中的值
$posts\u types\u selected
posts\u连接起来

更新 我在这里尝试了解决方案:

我得到:
视频(posts\u videos)
/
podacast(posts\u podcast)

但它被解释为字符串而不是变量


谢谢

这回答了你的问题吗?非常感谢。我尝试了这个解决方案,但得到了:注意:数组到字符串的转换。我的情况不同,我用木材。不管你用不用木材。请用代码更新问题u've triedOkay@DarkBee,我更新了我的答案您仍然需要将原始过滤器
length
添加到其中,例如
{{{{u context['posts'~item]|length}
    $object_category = get_queried_object();
    $current_category = $object_category->term_id;

    $posts_types_selected = array('videos', 'podcasts');
    $context['posts_types_selected'] = $posts_types_selected;
    
    foreach ($posts_types_selected as $post_type_selected) {
        $context['posts_'.$post_type_selected] = Timber::get_posts(array(
            'post_type' => array($post_type_selected),
            'post_status' => 'publish',
            'category__in' => array($current_category),
            'posts_per_page' => 10,
            'paged' => 1,
            'has_password' => FALSE
        ));
    }
<ul class="tab-menu">
    {% for item in posts_types_selected %}
        <li><a href="#" class="tab-control">{{ item }} ({{ 'posts_' ~ item|length }})</a></li>
    {% endfor %}
</ul>
<li><a href="#" class="tab-control">{{ item }} ({{ posts_videos|length }})</a></li>
<li><a href="#" class="tab-control">{{ item }} ({{ posts_podcasts|length }})</a></li>
{% for item in posts_types_selected %}
<li><a href="#" class="tab-control">{{ item }} ({{ _context['posts_' ~ item] }})</a></li>
{% endfor %}
{% for item in posts_types_selected %}
<li><a href="#" class="tab-control">{{ item }} ({{ 'posts_' ~ item }})</a></li>
{% endfor %}