これは私が持っている標準の HTML コードで、基本的に 2 つの異なる方法で投稿を表示する Wordpress ループにマージしようとしています。ユーザーが投稿を表示する2つの方法のいずれかを選択するために、より多くのフィールドプラグインを使用しています。1) 大を選択した場合、投稿は div クラス「大リンク」でラップされます 2) ユーザーが「小」を選択した場合、クラス「groupOflinks」の div が作成され、投稿は div クラス「smallLink」でラップされます'。1 つの「groupOflinks」div 内に保持できるのは、4 つの「smallLink」div/投稿のみです。小さい投稿が 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; ?>