如果我理解得很好,下面的代码片段应该可以满足您的需要。
我假设您的“gallery area”分类法中有四项,并且您应用于div的类必须相应地改变(即span\\u 1\\u of\\u 4必须变成span\\u 2\\u of\\u 4,等等)。
<?php
$gt_args = array(\'fields\' => \'ids\');
$terms = get_terms(\'gallery-area\', $gt_args); //retrieve ID of the terms of \'gallery-area\' taxonomy
$counter = 1;
foreach ($terms as $term){ //for each term (i.e. gallery-area-1, 2, 3 and 4) contained in $terms
$gp_args = array(
\'post_type\' => \'gallery-section\',
\'gallery-area\' => $term ,
);
$all_posts = get_posts( $gp_args ); //get all posts
$cover_post = $all_posts[0]; // take only the first one
echo \'<div class="col span_\' . $counter . \'_of_4 gallery_block">\';
?>
<a href="<?php get_permalink($cover_post->ID); ?>"> //$cover_post is a post object
<?php $cover_post->post_title ?>
</a>
</div>
<?php
$counter++;
}
?>
请注意
$cover_post
是一个
post object;
EDIT 在get\\u post中,术语ID可能不会像这样工作。您可能需要尝试使用以下参数,而不是上面的参数。让我知道。。
$gp_args = array(
\'post_type\' => \'gallery-section\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'gallery-area\',
\'terms\' => $term,
),
),
);