• Hi there,

    I have searched these forums but haven’t yet found a solution to this.

    Basically, I have two different sections in my website. A Blog, and a News page.

    I would like to display a sidebar on each of those pages which links to a category specific Archive (by month).

    For example, I’d like to have a News Archive (by month) down the right hand side of my News page which people can click on and it will take you to an Archive of all the news posts. Same for Blog.

    How can you do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter chrischickenwire

    (@chrischickenwire)

    I’ve found the below code on another thread which apparently needs to be put in the functions.php file. This code will apparently exclude certain categorys from the archive, and then I can pull the archive in the same way as normal.

    Problem is, I’ve tried just pasting it into the functions.php file but it corrupts the site and the site no longer opens. Do I have to place in specific tags, or in a certain place?

    add_filter( 'getarchives_where', 'customarchives_where' );
    add_filter( 'getarchives_join', 'customarchives_join' );
    
    function customarchives_join( $x ) {
    
    	global $wpdb;
    
    	return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
    
    }
    
    function customarchives_where( $x ) {
    
    	global $wpdb;
    
    	$exclude = '1'; // category id to exclude
    
    	return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)";
    
    }

    Make sure you’re posting it in BEFORE the PHP that closes the functions file. So that code would have after it the following

    ?>

    Thread Starter chrischickenwire

    (@chrischickenwire)

    So I’ve posted that in my functions.php page, and “Excluded” all the categories that I don’t want, but that doesn’t seem to have done anything. Any more help would be great?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category specific Archive’ is closed to new replies.