Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Header configuration & styling (http://forum.bytesforall.com/forumdisplay.php?f=15)
-   -   How to show alternating items of two categories on one page (http://forum.bytesforall.com/showthread.php?t=4011)

Sakshin Oct 22, 2009 06:14 AM

How to show alternating items of two categories on one page
 
I' made something myself but it comes out as a mess. have a look at newspiration.com/news/archive/ and you see what I mean. Below is the template I used but it doesn't give me the result I would like to see; alternating items of two categories on one page. Isn't there a neater way of doing this with perfect result?

<?php
/*
Template Name: twocol_archive
*/
?>

<?php /* get all options: */
include (TEMPLATEPATH . '/functions/bfa_get_options.php');
get_header(); ?>

<div class="txtboxarchive1">

<p><h3>This week's inspiring news</h3></p>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=news&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=inspiration&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?><br />
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=news&showposts=1&offset=1' );
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=inspiration&showposts=1&of fset=1');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?><br />
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=news&showposts1&offset=2') ;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=inspiration&showposts1&off set=2');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?><br />
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=news&showposts=1&offset=3' );
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=inspiration&showposts=1&of fset=3');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?><br />
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=news&showposts=1&offset=4' );
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php } ?>

<?php if ( is_page('197') ) { ?>
<?php $my_query = new WP_Query('category_name=inspiration&showposts=1&of fset=4');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; ?>
<?php } ?>

<?php /* If there are any posts: */
if (have_posts()) : $bfa_ata['postcount'] == 1; /* Postcount needed for option "1 first posts full posts" */ ?>

</div>


<div class="clear"></div>
<?php /* END of: If there are any posts */
else : /* If there are no posts: */ ?>

<?php /* This outputs the "Not Found" content, if neither posts, pages nor attachments are available for the requested page.
This can be edited at Atahualpa Theme Options -> Style & edit the Center column */
bfa_center_content($bfa_ata['content_not_found']); ?>

<?php endif; /* END of: If there are no posts */ ?>



<?php get_footer(); ?>

juggledad Oct 22, 2009 06:23 AM

I don't know if this is because of a typo during the copy and paste into the post, but the '&offset' in several of your WP_query's is '&off set' <- note the blank. If that is in the code, try removing it.

Sakshin Oct 22, 2009 06:39 AM

It's a copy/paste thing. In the file itself it's without the whitespaces. Any further advice?

juggledad Oct 22, 2009 06:49 AM

I'm not sure what you are trying to do. Do you only want one item from each and have them alternate? Saying someting is a mess may make sence to you, but for someone else looking at the issue for the first time, how do I know what you mean by mess?

Try to be specific as to what the problem is.

Sakshin Oct 22, 2009 07:15 AM

My appologies if I'm not clear enough.
The result you can see here at n e w s p i r a t i o n . c o m / n e w s / a r c h i v e /

The idea is that on one page we get two catergories. The posts will be placed every friday and have to be shown above eachother. The last post of category news, the last post of category inspiration, the second last post of news, the second last post of inspiration, etc. Untill it fills the whole page.
To achief this I work with specific calls of catergories and to have them in the order I want I use the offset; the offset=1, offset=2 etc.
But somehow the end result is not at all like this, only the first three posts show up like this and then it becomes a mess and even double posts appear...
I feel I need to throw some code away from the file, but what?

juggledad Oct 26, 2009 09:16 AM

I think you are running into an issue where your putting info out, and so is 'The LOOP'

Try putting this at the top of 'The LOOP'
HTML Code:

<?php if (!is_page('197') ) { ?>
and this at the bottom of 'The LOOP'
HTML Code:

<?php } ?>

Sakshin Nov 2, 2009 01:54 PM

I did what you suggested and the loop look like this now;

<?php if (!is_page('197') ) { ?>
<?php /* Post Container starts here */ if ( function_exists('post_class') ) { ?>
<div <?php if ( is_page() ) { post_class('post'); } else { post_class("$odd_or_even"); } ?> id="post-<?php the_ID(); ?>">
<div <?php if ( is_category() ) { post_class('post'); } else { post_class("$odd_or_even"); } ?> id="post-<?php the_ID(); ?>">

<?php } else { ?>
<div class="<?php echo ( is_page() ? 'page ' : '' ) . $odd_or_even . ' post" id="post-'; the_ID(); ?>"> <?php } ?>
<?php bfa_post_kicker('<div class="post-kicker">','</div>'); ?>
<?php bfa_post_headline('<div class="post-headline">','</div>'); ?> <?php bfa_post_byline('<div class="post-byline">','</div>'); ?>
<?php bfa_post_bodycopy('<div class="post-bodycopy clearfix">','</div>'); ?>
<?php bfa_post_pagination('<p class="post-pagination"><strong>'.__('Pages:','atahualpa').'</strong>','</p>'); ?>
<?php bfa_post_footer('<div class="post-footer">','</div>'); ?> </div>
<!-- / Post -->
<?php } ?>

I even tried to delete the whole loop but that gave other problems on the site...
What to to next? ;)

Sakshin.

Sakshin Nov 2, 2009 01:56 PM

So i forgot to write in the above message that the end result is the same, nothing changed.

Sakshin Nov 16, 2009 08:06 AM

Hello jugledad. Are you there? Can you shine some light on this issue? Please. ;)


All times are GMT -6. The time now is 03:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.