我在wordpress中有一個自定義函數,下面的代碼用於顯示自定義分類的縮略圖。我想實現的是,我想在每六張圖像後動態插入一個div class="row"
。我如何去做這件事?在wordpress中動態插入div中的div
$max = 10; //number of categories to display
$taxonomy = 'cp_recipe_category';
$terms = get_terms($taxonomy, 'hide_empty=1');
// Random order
shuffle($terms);
// Get first $max items
$terms = array_slice($terms, 0, $max);
// Sort by name
usort($terms, function($a, $b){
return strcasecmp($a->name, $b->name);
});
// Echo random terms sorted alphabetically
if ($terms) {
foreach($terms as $term) {
echo'<div class="vc_col-sm-2 wpb_column vc_column_container ">';
echo'<img src="'; echo z_taxonomy_image_url($term->term_id); echo'" />';
echo '<p><a href="' .get_term_link($term, $taxonomy) . '" title="' . sprintf(__("View all posts in %s"), $term->name) . '" ' . '>' . $term->name.'</a>
</p> ';
echo'</div>';
}
}