WordPress.org

Ready to get started?Download WordPress

Forums

To go post from a category - Imbalance theme (1 post)

  1. pastinpresent
    Member
    Posted 2 years ago #

    Hi there,

    I'm using the Imbalance theme and wonder if it might be possible to adapt the archive.php script to automatically check how many results will be returned and then direct straight to a post if there is just the one in this category.

    I found this code elsewhere on the forum, but can't work out how it can be built in to Imbalance without causing major errors.

    <?php
    	if(have_posts()) :
    		$category = get_the_category();
    		if ($category[0]->category_count == 1) :
    			while (have_posts()) : the_post();
    			wp_redirect(get_permalink($post->ID));
    			endwhile;
    		else :
    			include(TEMPLATEPATH . '/index.php');
    		endif;
    	endif;
    ?>

    Here's the Imbalance archive.php code:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    I've tried placing the code in various parts but it just ends up with a blank screen. Any ideas? I'm stumped...

Topic Closed

This topic has been closed to new replies.

About this Topic