ThemeShaper Forums » Acamas

[closed]

Acamas: Exclude category from posts shown

(23 posts)
  • Started 5 years ago by Queequeg
  • Latest reply from gretchenlouise
  1. Queequeg
    Member

    Hi!

    I would like to exclude posts from a certain category and prevent them from showing up within the list of posts on the main page. What would be the code to achieve this, and where would i place it? Thanks!

    Posted 5 years ago #
  2. Line 294 of functions.php looks like this:

    $query->set('cat', $acms_featurecategory);

    Modify it so that it looks like this:

    $query->set('cat', "$acms_featurecategory,-4");

    Where 4 is the ID of your category (hover over a category on the manage category page and look at the URL to find the ID). It could be 4, 5, 6, 18—whatever.

    Posted 5 years ago #
  3. Queequeg
    Member

    Thanks so much, Ian! I'm loving the theme so far.

    Posted 5 years ago #
  4. Thanks. Do me a favor though, stay off the Pequod. I hear bad things about their Captain.

    Posted 5 years ago #
  5. Queequeg
    Member

    LOL!

    Actually, i confess, my username is more a tribute to the name of Scully's dog in the X-Files than it is Moby Dick ;)

    Posted 5 years ago #
  6. theandyreport
    Member

    I have, essentially the exact same concern - except that I am not working in Acamas (working in my own child theme of Thematic). So far, I've been able to make all my changes successfully using filters and hooks in my own functions.php file. I'd like to continue to do things this way, rather than get my hands dirty in my index file or in the loop. I'm fairly sure that 'thematic_indexloop()' is "where the action is" -- I'm jsut not certain how/where to tweak it.

    So to restate the problem:
    I have a specific category called articles. I do not want any of the posts in this category to appear on index.php. The only way people should be able to read the 'articles' category is by clicking on the category on the sidebar.

    If the solution is already out there, I've missed it and I apologize. Any direction would be greatly appredciated!!!

    -Andy

    Posted 5 years ago #
  7. Hi,

    .. and I guess that if a single post is called from this category all posts should stay in this category?! ;)

    Will be back in a couple of minutes!

    Chris

    Posted 5 years ago #
  8. OK .. I'm back ..

    First of all, let's strip everything that isn't needed in your index:

    function exclude_category($query) {
    	if ( $query->is_feed || $query->is_home ) {
    		$query->set('cat', '-252');
    	}
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    This will remove the category 252 from the index.

    .. and now let's do some magic ..

    function childtheme_previous_post_link_args($args) {
    		global $wp_query;
    		$category = get_the_category();
    		echo $category->cat_ID;
    		if (in_category('252')) {
    				$args = array ('format'              => '%link',
    											 'link'                => '<span class="meta-nav">&laquo;</span> %title',
    											 'in_same_cat'         => TRUE,
    											 'excluded_categories' => '');
    			}
    		else {
    				$args = array ('format'              => '%link',
    											 'link'                => '<span class="meta-nav">&laquo;</span> %title',
    											 'in_same_cat'         => FALSE,
    											 'excluded_categories' => '252');
    		}
    		return $args;
    }
    add_filter('thematic_previous_post_link_args', 'childtheme_previous_post_link_args');
    
    function childtheme_next_post_link_args($args) {
    		global $wp_query;
    		$category = get_the_category();
    		echo $category->cat_ID;
    		if (in_category('252')) {
    				$args = array ('format'              => '%link',
    											 'link'                => '%title <span class="meta-nav">&raquo;</span>',
    											 'in_same_cat'         => TRUE,
    											 'excluded_categories' => '');
    			}
    		else {
    				$args = array ('format'              => '%link',
    											 'link'                => '%title <span class="meta-nav">&raquo;</span>',
    											 'in_same_cat'         => FALSE,
    											 'excluded_categories' => '252');
    		}
    		return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');

    If a single post from the category 252 is opened, next / previous post link will stay in the same category .. and the category will be stripped for next / previous post link if a post is opened from your index.

    Chris

    Posted 5 years ago #
  9. theandyreport
    Member

    ".. and I guess that if a single post is called from this category all posts should stay in this category?! ;)"

    I hadn't even thought of that! Wow. Yes that too. Thank you. I'm new at all of this wordpress stuff, but I must say the resources I have found on Themeshaper and these forums are absolutely awesome.

    Thanks for the time Chris, I will try your solution and post back to let you know for sure that this issue has been resolved.
    -Andy

    Posted 5 years ago #
  10. theandyreport
    Member

    It worked most awesomely. Thanks for your help, Chris.
    -Andy

    Posted 5 years ago #
  11. amygail
    Member

    I'm able to use this code to remove a category from my posts page -

    but the problem is that I have another custom page template that queries posts (that are also in the category that I removed) based on custom fields.

    When I add this code - the posts no longer appear on the other page or anywhere else that I've queried them (they do, however, appear on the category archives page)

    my brain hurts - I hope this makes sense.
    Thanks in advance.

    (I'm not using Acamas either - it's my own child theme)

    Posted 5 years ago #
  12. Hi Amy,

    it should show up everywhere except the RSS feed and your posts page .. need to think about it .. or get more coffee? (5 am)

    Chris

    Posted 5 years ago #
  13. amygail
    Member

    early bird!

    Maybe it has something to do with the way I'm querying posts my page templates (I'm really just a hack) this is what I've got for this page
    http://burntsugarindex.com/sugar/the-artists/

    It was working fine until I added the new function

    <?php
    /*
    Template Name: band-members
    Description:a custom template for the page listing the band members*/
    
    get_header(); ?>
    
    	<div id="container">
    		<div id="content">
    
    <div id="current-members">
    
    		<h2 class="entry-title">Current Members</h2>
    		<?php query_posts('post_type=post&category=20&meta_key=member&meta_value=current'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="artist">
    
    		<?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'image_class' => 'artistthumb' )); } ?>
    	 	<h3 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'thematic'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?> : <?php echo get_post_meta($post->ID, 'instrument', TRUE); ?></a></h3>
    
    	 			 </div><!-- artist -->
    				<?php endwhile; wp_reset_query(); ?>
    				<?php endif; ?>
    				</div><!-- current-members -->
    
    <div id="past-members">
    
    		<h2 class="entry-title">Past Members</h2>
    		<?php query_posts('post_type=post&meta_key=member&meta_value=past'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="artist">
    		<?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'image_class' => 'artistthumb' )); } ?>
    	 	<h3 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'thematic'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?></a></h3>
    	 			 </div><!-- artist -->
    				<?php endwhile; wp_reset_query(); ?>
    				<?php endif; ?>
    				</div><!-- past-members -->
    
    		</div><!-- #content -->
    	</div><!-- #container -->
    
    <?php get_footer() ?>
    Posted 5 years ago #
  14. amygail
    Member

    Hey Again Chris,
    I removed the categories from my blog by filtering the loop like so:

    function my_index_loop() {
      /* Count the number of posts so we can insert a widgetized area */ $count = 1;
    		while ( have_posts() ) : the_post() ?>
    		<?php if (in_category( array( '20', '4' )) && is_home() ) continue; ?>
    
    			<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
        			<?php thematic_postheader(); ?>
    				<div class="entry-content">
    <?php thematic_content(); ?>
    
    				<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    				</div>
    				<?php thematic_postfooter(); ?>
    			</div><!-- .post -->
    
    				<?php comments_template();
    
    				if ($count==$thm_insert_position) {
    						get_sidebar('index-insert');
    				}
    				$count = $count + 1;
    		endwhile;
    
    }
    add_action('thematic_indexloop', 'my_index_loop');

    "Now I just have to figure out how to remove them from the "next/prev" links"

    Posted 4 years ago #
  15. Hi Amy,

    if you're excluding 20 and 4, it should be something like:

    function childtheme_next_post_link_args($args) {
        global $wp_query;
        $category = get_the_category();
        echo $category->cat_ID;
        if ((in_category('4') || (in_category('20')) {
            $args = array ('format'              => '%link',
    		       'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => TRUE,
                           'excluded_categories' => '');
        } else {
            $args = array ('format'              => '%link',
                           'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => FALSE,
                           'excluded_categories' => '4, 20');
        }
        return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');

    The previous post link thing is similar except of the CSS markup

    Chris

    Posted 4 years ago #
  16. amygail
    Member

    Hey Chris,
    THANK you so much!
    I'm working through this - but I'm going to post it just in case you're still online

    I'm getting this error

    Parse error: syntax error, unexpected '{' in /nfs/c01/h08/mnt/1886/domains/burntsugarindex.com/html/sugar/wp-content/themes/burntsugar/functions.php on line 98

    which would be this line:
    if ((in_category('4') || (in_category('20')) {

    any thoughts?
    a

    Posted 4 years ago #
  17. .. checking

    Posted 4 years ago #
  18. Sorry .. too many brackets .. should be:

    if (in_category('4') || in_category('20')) {

    Chris

    Posted 4 years ago #
  19. The whole thing:

    function childtheme_next_post_link_args($args) {
        global $wp_query;
        $category = get_the_category();
        echo $category->cat_ID;
        if (in_category('4') || in_category('20')) {
            $args = array ('format'              => '%link',
    		       'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => TRUE,
                           'excluded_categories' => '');
        } else {
            $args = array ('format'              => '%link',
                           'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => FALSE,
                           'excluded_categories' => '4, 20');
        }
        return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');
    Posted 4 years ago #
  20. amygail
    Member

    Thank you so much! I have it working now.

    I did discover that I have to separate the 'excluded' categories with 'and'

    like so:

    function childtheme_next_post_link_args($args) {
        global $wp_query;
        $category = get_the_category();
        echo $category->cat_ID;
        if (in_category('4') || in_category('20')) {
            $args = array ('format'              => '%link',
    		       'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => TRUE,
                           'excluded_categories' => '');
        } else {
            $args = array ('format'              => '%link',
                           'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => FALSE,
                           'excluded_categories' => '4 and 20');
        }
        return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');

    Danke, sind Sie mein Held

    Posted 4 years ago #
  21. Hi all, thanks for all the work on this but I'm having trouble getting it to work. Here is my code in functions.php:

    //exclude categories that don't need to display in archives (focal areas and new developments
    function exclude_category($query) {
    	if ( $query->is_feed || $query->is_single ) {
    		$query->set('cat', '-14,-15,-16,-17,-18,-19,-1');
    	}
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    
    function childtheme_next_post_link_args($args) {
        global $wp_query;
        $category = get_the_category();
        echo $category->cat_ID;
        if (in_category('14') || in_category('15') || in_category('16') || in_category('17') || in_category('18') || in_category('19') || in_category('1') ) {
            $args = array ('format'              => '%link',
    		       'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => TRUE,
                           'excluded_categories' => '');
        } else {
            $args = array ('format'              => '%link',
                           'link'                => '%title <span class="meta-nav">&raquo;</span>',
                           'in_same_cat'         => FALSE,
                           'excluded_categories' => '14 and 15 and 16 and 17 and 18 and 19 and 1');
        }
        return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');

    As you can see I'm trying to exclude a number of categories. Does anybody have any ideas as to why this isn't working? I still have posts from categories I'm trying to exclude showing up in my next/prev links.

    Thanks for any help you can provide,
    Jonah

    Posted 4 years ago #
  22. Hello everyone, just had to pull up this old post - my problem is not about the 'Acamas' childtheme. It's my own childtheme I developed out of the childtheme provided with thematic.

    I used this bit of code to tie a category to a page and to exclude this category on the main/index page.

    // custom-Page-Query
    function child_theme_custom_query() {
    
        	if (is_page('2')) { // '2' = id # of page
    
    	$limit = get_option('posts_per_page');
        	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            // '19' is category id #
        	query_posts('cat=19' . '&showposts=' . $limit=10 . '&paged=' . $paged );
    
        	$wp_query->is_archive = true; $wp_query->is_home = false;
        	}
    }
    
    add_action('thematic_above_indexloop', 'child_theme_custom_query');
    
    // exclude Cat on Index
    function exclude_category($query) {
    	if ( $query->is_feed || $query->is_home ) {
    		$query->set('cat', '-19');
    	}
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    On the page I want that category to be displayed I used this header and assigned that template to the page in the admin panel of wordpress:

    <?php
    /*
    Template Name: photodiary
    */
    include( TEMPLATEPATH . '/index.php' ); //this loads the thematic parent framework index.php
    ?>

    It works fine, wenn I browse my site - but when I browsed the page #2 (see above) and then go back to the index the posts are messed up. Only the first 3 Posts are shown correctly, the rest is somehow 'leaving its divs'. They are printed over the complete width of the page.
    I'm somehow unable to detect the mistake or malcode... :/

    Would be glad if anybody could help a bit.

    Posted 4 years ago #
  23. gretchenlouise
    Member

    Super-easy code for the functions.php! Thank you. I spent hours looking in other forums and blogs before it dawned on me to look in the forum for my theme!

    Now what I'm looking to do is remove "This entry was posted in Category" from only the posts that show my hidden category.

    http://www.spanishseo.org/block-and-remove-wordpress-categories says:

    replace <?php the_category(', ') ?> with the following code:
    <?php foreach((get_the_category()) as $cat) { if (!($cat->cat_ID=='52')) echo 'category_nicename . '/">'. $cat->cat_name . '' . ', '; } ?>

    But where do I find/edit this for my post footer in Thematic? Thank you!

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.