这是我拥有的标准 HTML 代码,我正在尝试将其合并到一个 Wordpress 循环中,该循环基本上以两种不同的方式显示帖子。我正在使用更多字段插件供用户选择显示帖子的两种方式之一。1) 如果他们选择大,则帖子将使用 div 类“大链接”进行包装 2) 如果用户选择“小”,则会创建一个具有“groupOflinks”类的 div,并将帖子使用 div 类“smallLink”包装'。一个 'groupOflinks' div 中只能保存 4 个 'smallLink' div's/posts。如果有超过 4 个小帖子,则会创建一个新的 'groupOflinks' div 并重复该过程。
这是我试图合并的 HTML 代码(大量评论):
<!-- Display one post within this container only & if there are more posts that have been chosen as Large, wrap them in the 'largeLink' div -->
<div class="largeLink">
<!-- post 1 content here -->
</div>
<div class="largeLink">
<!-- post 2 content here -->
</div>
<!-- If a post is defined as small within the admin panel (using more fields plugin)
display them within this 'groupoflinks' container
If 4 posts are already in this 'groupoflinks' container create a new container and populate with another 4 posts
Repeat -->
<div class="groupOfLinks">
<!-- This is a container that holds 4 posts only & if there are more posts that have been assigned as 'Small' create a new 'groupOflinks' container and populate with the next 4 -->
<div class="smallLink">
<!-- Post 4 content here -->
</div>
<div class="smallLink">
<!-- Post 5 content here -->
</div>
<div class="smallLink">
<!-- Post 6 content here -->
</div>
<div class="smallLink">
<!-- Post 7 content here -->
</div>
</div>
<div class="largeLink">
<!-- post 3 content here -->
</div>
<div class="largeLink">
<!-- post 8 content here -->
</div>
到目前为止,这是我的 WP 循环,它不太工作:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // Take the value defined with the 'Layout' field and change style accordingly
$layouttype = get_post_meta($post->ID, 'layout-type', true) ?>
<?php if ($layouttype == 'Small') { ?>
<div class="groupOfLinks">
<!--LOOP STYLE 1 GOES HERE-->
<?php $temp_query = $wp_query; // store it
$args = array(
'paged' => $paged, // paginates
'post_type'=>'post',
'order' => 'DESC'
);
$wp_query = new WP_Query($args);
while ($wp_query->have_posts()) : $wp_query->the_post();?>
<div class="smallLink">
<!-- Post content here -->
<h1><?php the_title(); ?></h1>
<?php the_content(''); ?>
</div>
<?php if (isset($wp_query)) {$wp_query = $temp_query;} // restore loop
endwhile; ?>
</div>
<?php } else { ?>
<!--LOOP STYLE 2 GOES HERE-->
<div class="largeLink">
<!-- post 1 content here -->
<h1><?php the_title(); ?></h1>
<?php the_content(''); ?>
</div>
<?php } ?>
<?php endwhile; ?>
<div>
<div><?php next_posts_link('« Older Entries') ?></div>
<div><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn’t here.</p>
<?php endif; ?>