Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Archive Pages with Genesis WordPress

  • SOLVED

I have a custom archive page on my site, [[LINK href="http://braziliangringo.com/archive/"]]visible here.[[/LINK]]

What I want to do is to separate this into 2 archive pages.

I want one archive page to have every post, except for posts from Category 90.

I want the second archive page to only have posts from Category 90.

How should I change the code to make the 2 templates for these custom pages?


function sk_page_archive_content() {

global $post;
echo '<ul class="archives">';
$lastposts = get_posts('numberposts=-1');
$year = '';
$month = '';
foreach($lastposts as $post) :
setup_postdata($post);

if(ucfirst(get_the_time('F')) != $month && $month != ''){
echo '</ul></li>';
}
if(get_the_time('Y') != $year && $year != ''){
echo '</ul></li>';
}
if(get_the_time('Y') != $year){
$year = get_the_time('Y');
echo '<li><h2>' . $year . '</h2><ul class="monthly-archives">';
}
if(ucfirst(get_the_time('F')) != $month){
$month = ucfirst(get_the_time('F'));
echo '<li><h3>' . $month . '</h3><ul>';
}
?>
<li>
<span class="the_date"><?php the_time('d') ?>:</span>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php
}

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

genesis();

Answers (1)

2015-08-04

Kyle answers:

Something like this would work

if( $post->ID == 1 ){ //This is your conditional so this should be set to the post ID you don't want to show category 90

$args = array( 'numberposts' => -1, 'category' => -90, );

}else{

$args = array( 'numberposts' => -1, 'category' => 90 );

}

$lastposts = get_posts( $args );


braziliangringo comments:

Should what you wrote replace this line?

$lastposts = get_posts('numberposts=-1');

Or should it replace something else as well?


Kyle comments:

Yup, just that line


braziliangringo comments:

Ok I got that working on this page:

http://braziliangringo.com/novo-arquivo/

Now how would I get the original archive page to not show those posts?


Kyle comments:

That would be a new question altogether.

My suggestion would be a pre_get_posts filter that adds in the category part above to the archive page

function exclude_category( $query ) {
if ( $query->is_post_type_archive('post') ) {
$query->set( 'cat', '-90' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );