Hi
This is what Im trying to accomplish:
Display four posts from one category and then one post from another category and so on:
cat 1
cat 1
cat 1
cat 1
cat 2
cat 1
cat 1
cat 1
cat 1
cat 2
...
I use two loops based on query posts inside the standard loop. It all works but my pagination fails. If I set post_per_page to for example ten, WP displays 10 posts of posts from both categories (ten posts from cat 1 ten posts from cat 2). I have limited the second category to only show post_per_page/4 but thats only a bad solution. I should also mention that I have a lot of categories and sub-categories that I dont display and in the beginning of the code I loop trough these and put them in arrays so the query know which posts to loop trough. Here is the code, any solutions??
<?php get_header(); ?>
<?php $postNum = 0; ?>
<?php $themeNum = 0; ?>
<?php $themeSpace = 4; ?>
<?php $bigPostThumb = 0; ?>
<?php
$postArray = array();
$themeAuthors = array();
$my_query = new WP_Query('cat=6');
while ($my_query->have_posts()) : $my_query->the_post();
if (is_sticky()) :
$post_ID = $post->ID;
array_push($postArray,$post_ID);
endif;
if (get_post_meta($post->ID, "author", false)) :
foreach((get_the_category()) as $category) {
if ($category->cat_ID != 6) {
$catIDs = $category->cat_ID;
$mykey_values = get_post_custom_values('author');
foreach ( $mykey_values as $key => $value ) {
${'catIDs'} = array(ID => $catIDs, author => $value );
}
array_push($themeAuthors,${'catIDs'});
}
}
$post_ID = $post->ID;
array_push($postArray,$post_ID);
endif;
?>
<?php endwhile; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$argPosts = array(
'showposts' => get_option('posts_per_page')-(get_option('posts_per_page')/$themeSpace),
'category__in' => array(3,4),
'paged'=>$paged,
);
$argThemes = array(
'showposts' => get_option('posts_per_page')/$themeSpace,
'cat' => 6,
'post__not_in' => $postArray,
'paged'=>$paged,
);
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (is_sticky()) : ?>
<!-----------------STICKY POST---------------------------->
<?php
foreach((get_the_category()) as $category) {
if ($category->cat_ID != 6) {
$catName = $category->cat_name;
$catID = $category->cat_ID;
$category_link = get_category_link( $category->cat_ID);
$post_ID = $post->ID;
}
};
?>
<div id="sticky-content"> <img src="<?php echo get_first_image() ?>" width="575" height="330" />
<div id="img-overlay">
<h2>" rel="bookmark" title="Permanent Link to <?php echo $catName; ?>">
<?php the_title(); ?>
</h2>
<div id="text">
<?php
ob_start();
the_content('');
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
ob_end_clean();
echo $postOutput;
?>
</div>
<div id="temaskribenter">
<div id="temaskribenter-header">Temaskribenter</div>
<?php
foreach ($themeAuthors as $i => $row) {
if ($row['ID'] == $catID) : ;
echo '
endif;
}
?>
</div>
</div>
<div class="theme-link">" rel="bookmark" title="Permanent Link to <?php echo $catName; ?>">Till temasidan »</div>
</div>
<?php else : ?>
<?php $my_query_regular = new WP_Query($argPosts);
while ($my_query_regular->have_posts()) : $my_query_regular->the_post();
if ($postNum < 4) : ;
if (in_array($post->ID, $do_not_duplicate_regular)) continue;
$do_not_duplicate_regular[] = $post->ID;?>
<!-----------------REGULAR POST---------------------------->
<?php
foreach((get_the_category()) as $category) {
if ($category->cat_ID != 3 && $category->cat_ID != 4) {
$catName = $category->cat_name;
$category_link = get_category_link( $category->cat_ID);
}
}
?>
<?php if (($paged < 2) && ($bigPostThumb < 1)) : ; ?>
<div class="big-post-thumb">
<div class="big-post-thumb-left"><img src="<?php echo get_first_image() ?>" width="278" height="197" />
<div class="overlay">
<div class="big-post-thumb-readmore"> " rel="bookmark" title="Permalänk till <?php the_title_attribute(); ?>">Läs mer »</div>
<?php echo $catName ?> bloggar om
<h2>" rel="bookmark" title="Permalänk till <?php the_title_attribute(); ?>">
<?php the_title(); ?>
</h2>
</div>
</div>
<?php $bigPostThumb++; elseif ($bigPostThumb == 1) : ?>
<div class="big-post-thumb-right"><img src="<?php echo get_first_image() ?>" width="278" height="197" />
<div class="overlay">
<div class="big-post-thumb-readmore"> " rel="bookmark" title="Permalänk till <?php the_title_attribute(); ?>">Läs mer »</div>
Läs senaste inlägget från
<h2>" rel="bookmark" title="Permalänk till <?php the_title_attribute(); ?>"> <?php echo $catName ?> </h2>
</div>
</div>
</div>
<?php $bigPostThumb++; else : ; ?>
<div id="post">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-header">
<div class="post-author">
<!-- Print a link to this category -->
" title="<?php echo $catName; ?>"><?php echo $catName; ?> </div>
<div class="post-date">Inlagd
<?php the_time('Ymj') ?>
</div>
</div>
<div class="post-img"> <img src="<?php echo get_first_image() ?>" width="120" height="85" /> </div>
<div class="post-content">
<h2>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?>
</h2>
<div class="post-excerpt">
<?php
ob_start();
the_content('');
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
ob_end_clean();
echo $postOutput;
?>
</div>
<div class="post-link"> ">Läs hela inlägget »</div>
<div class="comments-count">
<?php comments_popup_link('0', '1', '%'); ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php $postNum++; ?>
<?php endif ;?>
<?php endwhile; ?>
<!-----------------THEME POST---------------------------->
<?php $my_query_theme = new WP_Query($argThemes);
while ($my_query_theme->have_posts()) : $my_query_theme->the_post();
if ($themeNum < 1) : ;
if (in_array($post->ID, $do_not_duplicate_theme)) continue;
$do_not_duplicate_theme[] = $post->ID; ?>
<?php
foreach((get_the_category()) as $category) {
if ($category->cat_ID != 6) {
$catName = $category->cat_name;
$catID = $category->cat_ID;
$category_link = get_category_link( $category->cat_ID);
}
}
?>
<div id="sticky-content"> <img src="<?php echo get_first_image() ?>" width="575" height="330" />
<div id="img-overlay">
<h2>" rel="bookmark" title="Permanent Link to <?php echo $catName; ?>">
<?php the_title(); ?>
</h2>
<div id="text">
<?php
ob_start();
the_content('');
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
ob_end_clean();
echo $postOutput;
?>
</div>
<div id="temaskribenter">
<div id="temaskribenter-header">Temaskribenter</div>
<?php
foreach ($themeAuthors as $i => $row) {
if ($row['ID'] == $catID) : ;
echo '
endif;
}
?>
</div>
</div>
<div class="theme-link">" rel="bookmark" title="Permanent Link to <?php echo $catName; ?>">Till temasidan »</div>
</div>
<?php $themeNum++; ?>
<?php endif ;?>
<?php endwhile; $postNum = 0; $themeNum = 0; ?>
<?php endif ;?>
<?php endwhile; ?>
<!-----------------NAVIGATION---------------------------->
<?php if (function_exists('wp_pagenavi')) : ?>
<div class="pagenavi">
<?php wp_pagenavi( 10, false); ?>
</div>
<?php endif; ?>
<?php else : ?>
<h2>Det du sökte hittades tyvärr inte</h2>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>