0
我使用木材的Wordpress和ACF。Wordpress /木材/ ACF爲每個圖像創建幻燈片
我想創建一個結構類似:
<div class="section" id="section1">
<div class="slide slide0">
<div class="image-container" data-type="home" data-currentslide="1" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
<div class="slide slide1">
<div class="image-container" data-type="project" data-currentslide="2" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
<div class="slide slide2">
<div class="image-container" data-type="project" data-currentslide="3" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
</div>
<div class="section" id="section2">
<div class="slide slide0">
<div class="image-container" data-type="project" data-currentslide="1" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
<div class="slide slide1">
<div class="image-container" data-type="project" data-currentslide="2" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
<div class="slide slide2">
<div class="image-container" data-type="project" data-currentslide="3" data-maxslides="3" data-title="DEMO" data-project="Sweater Collection (Hamburg, 2017)">
<img src="img/myimage.jpg">
</div>
</div>
</div>
我創建了一個自定義文章類型稱爲「projets」。我想爲每個「projets」帖子創建一個div。
$context = Timber::get_context();
$context['projets'] = Timber::get_posts(array('post_type' => 'projets', 'posts_per_page' => '-1'));
這個循環做工精細
{% for projet in projets %}
<div class="section" id="section{{loop.index}}">
</div>
{% endfor %}
在我創建了圖像的中繼場每一個職位(稱爲 「project_imgs」)。每張圖片必須創建一張幻燈片。但我沒有設法創建第二個循環。我可以幫助建立我的第二個循環嗎?
{% for slide in slides.get_field('project_imgs') %}
<div class="slide slide{{ loop.index0 }}">
<div class="image-container" data-type="home" data-currentslide="1" data-maxslides="1" data-title="Title" data-project="+49(0)1520 8819162 Berlin&Hamburg (GERMANY)">
<img src="img/myimage.jpg">
</div>
</div>
{% endfor %}
另一個問題是遞增data-currentslide="1" data-maxslides="1"
謝謝你的幫助。是的,maxslides代表每個項目中圖像的最大數量。不幸的是,這是行不通的。我有一個名爲project_imgs的中繼器字段,我有兩個圖像域名爲project_img_desktop和project_img_mobile,我迷路了 – Xroad
我用屏幕截圖更新了我的問題,以顯示我的acf結構 – Xroad
@xroad我不知道你打算如何將圖像用於桌面和移動設備,但使用幻燈片的桌面圖像替換「」與「」 – Junaid