Modifying the Spectrum Theme to Display Specific Categories on Recent and Older Post Sections

Print Friendly, PDF & Email

I encountered a scenario where I needed the WooTheme Spectrum to display a specific category on the Recent Posts section of the homepage and a second specific category on the Older Posts section of the homepage.

By default, Spectrum takes all recent posts not displayed in the top slider and displays the posts in descending order by date. I wanted to keep the descending order, but only have specific categories display. By doing this, I can have Category 1 display large thumbnails as seen on the right, and Category 2 display smaller thumbnails with less visual emphasis.

I began by opening up index.php of the Spectrum theme files. I located the first args array relevant to “Recent Posts”:

$args = array( ‘post__not_in’ => $exclude,
‘category__not_in’ => $cat_exclude,
‘paged’=> $paged );

I commented out the original in case I needed to quickly restore it at a later date and inserted the following line:

$args = array( ‘cat’ => 1 );

The array now looks like:

<?php
// Exclude stored duplicates
$exclude = get_option(‘woo_exclude’);
// Exclude categories
//$cat_exclude = array();
$cats = explode(‘,’,get_option(‘woo_home_exclude’));
foreach ($cats as $cat)
$cat_exclude[] = $cat;
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args = array( ‘cat’ => 1 );
/* original code replaced by previous line $args = array( ‘post__not_in’ => $exclude,
‘category__not_in’ => $cat_exclude,
‘paged’=> $paged ); */
query_posts($args);
?>

Now its time for the second section, “Older Posts.”

After locating this code:

$args = array( ‘post__not_in’ => $exclude,
‘posts_per_page’ => $ppp,
‘offset’ => $count,
‘category__not_in’ => $cat_exclude );

I commented it out and inserted this code one line above:

$args = array( ‘cat’ => 2 );

The second php array now looks like:

<!– OLDER POSTS LOOP –>
<?php
if (!is_paged() && get_option(‘woo_recent_entries’) < get_option(‘posts_per_page’)) :
$counter = 0;
$small_thumb_h = get_option(‘woo_small_thumb_h’);
$small_thumb_w = get_option(‘woo_small_thumb_w’);
if(empty($small_thumb_h) OR empty($small_thumb_w)) { $small_thumb_h = 60; $small_thumb_w = 60;}
$small_placeholder_src = get_option(‘woo_small_placeholder’);
$count2 = 0;
$ppp = get_option(‘posts_per_page’) – $count;
$args = array( ‘cat’ => 2 );
/* original code replaced by previous line $args = array( ‘post__not_in’ => $exclude,
‘posts_per_page’ => $ppp,
‘offset’ => $count,
‘category__not_in’ => $cat_exclude );*/
$my_query = new WP_Query($args);
if($my_query->have_posts()) : ?>

After saving and uploading the modified file, the homepage now properly displayed each of the two categories in the Recent and Older posts sections.

No comments yet.

Leave a Reply