我有点复杂design。
我想用CPT输出它。这是我在wp_query中的CPT:
FROM
在2个帖子之后我想添加一个静态img和4个帖子后另一个静态和另外2个帖子后另一个静态img等。
我愿意接受有关更好方法的建议。
我正在考虑另一种方法。也许使用Visual composer来构建网格?
答案 0 :(得分:0)
嘿Darren这是逻辑,我认为你可以修改我的函数并在你的代码中实现它。
/**
* Management Team Shortcode
**/
function team_query() {
$args = array(
'posts_per_page' => -1,
'post_type' => 'management-team',
'order' => 'ASC',
);
$posts = get_posts( $args );
if ( !empty( $posts ) ) {
$flag = 0;
foreach ($posts as $counter => $p) {
$counter++;
if ( $flag <= 2 ) {
$flag++;
}
$title = get_the_title($p->ID);
$link = get_the_permalink($p->ID);
$featured_img = get_the_post_thumbnail_url( $p->ID, 'full' );
$html_out = '<article class="recent-project" style="background: url(' . $featured_img . ') no-repeat center center; background-size: cover;">';
// Do stuff with each post here
if ( $flag % 2 == 0 ) {
//add image after second post like
// $html .= <img src="css/images/myimage1.png" alt="" />
}
if ( $counter % 6 == 0 ) {
$flag = 0;
//add image after sixth post like
// $html .= <img src="css/images/myimage2.png" alt="" />
}
$html_out .= '<div class="container"><div class="meta-project"><h6>Latest Project</h6>' . '<h2>' . $title . '</h2>' . '<a class="btn btn-lg btn-tertiary" href="' . $link . '">' . 'Discover' . '</a></div></div>';
$html_out .= '</article>';
}
} else {
// No results
echo "Nothing to show";
}
return $html_out;
}
干杯:)