我有一個wordpress循環,在div中輸出我的帖子。那些div有這些類.col1,.col2,.col3
。輸出看起來是這樣的:在一個包裝div中包裝多個div的類?
現在我需要一個單個包裝專區內包裝這些div。
例如所有.col1
應的單個包裝的div內包裹.left
類,.col2
應包裝具有單個分度.middle
類和.coll3
應用的div類「.right
」纏繞。
我不知道我的頁面中有多少個div。
所以最終的輸出應該是這樣的:
我的循環如下所示:
<?php
$col = 1; // Let's create first column.
if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div <?php post_class('col' . $col); ?> id="post-<?php the_ID(); ?>">
<?php if (1 === $col) {// If column 1 create first row.
echo '<div class="row">';
}
?>
<?php if (2 === $col) {// If column 2 create second row.
echo '<div class="row2">';
}
?>
<?php if (3 === $col) {// If column 3 create third row.
echo '<div class="row3">';
}
?>
<!--Get the Three Columns Content -->
<?php get_template_part('template-parts/content', 'three-columns'); ?>
<?php /* Close Three Column Layout Div's */
if (1 === $col) {
$col = 2;
echo '</div>';
} else if (2 === $col) {
$col = 3;
echo '</div>';
} else if (3 === $col) {
$col = 1;
echo '</div>';
}
endwhile; ?>
<?php else : ?>
<?php get_template_part('template-parts/content', 'none'); ?>
<?php endif;?>
可以這樣用PHP只做不js
?謝謝!!
嗯嘗試過,但它是不工作...我猜' while(have_posts)'should'while(have_posts())'說實話我不知道如何將div的類存儲到'$ columns = array();'你能提供一個例子嗎?是的,我用PHP:( –
)我不是很熟悉Wordpress,所以我不能真正地幫助那個部分,這是相當通用的代碼,所以你應該能夠提取你需要的東西,只要試驗,直到它到達那裏。 。 – danielson317