• Hi,

    The plugin allow users to hide the events from showing on the homepage, but when you are on single post views and browse through the posts, the events appear.
    I want the events to show only in the calendar views (in that case, for events/list.php and events/single.php)
    I also don’t want the events to appear in the Archives. They are counted in the archive by months.

    How do I remove the Events category from showing in the single post views?
    I tried to use query_posts to exclude a category, but it doesn’t work in the single.php file. (Then the page displays one post for each categories except the excluded category).

    Same question for the archive.

    Sebastien

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Sebastien,

    For single.php in your theme, the following works to get the loop right:

    <?php
    $eventsCatId = get_cat_ID( 'Events' );
    query_posts($query_string.'&cat=-'.$eventsCatId);
    ?>

    That keeps the query already set by WP and appends your category exclusion. I’m guessing the same technique will work for archive.php.

    In single view, the previous and next post links will still include Events posts. Here is the generic markup for the previous post link, which allows for category exclusion.

    <?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = ''); ?>

    The reference: https://codex.www.ads-software.com/Template_Tags/previous_post_link

    Let us know if that does it. I bet others would like a similar setup.

    Justin

    Thread Starter Sébastien Thiroux

    (@mmarauder)

    Hi Justin,

    Thanks for your help!
    Removing the events from the single post view works just with the previous and next post links removing the category. (I didn’t think about that one)

    I also tried the first snippet of code for the archive, I can’t get it to work.
    I usually use the query_post at the beginning of a loop, in that case I don’t know where to place as it I don’t have a loop in my archive.
    Here is the code I use:

    <?php /* Template Name: All Archives */ ?>
    
    <?php get_header(); ?>
    	<div id="content">
    
    		<div id="countryMain">
    
    			<h2 id="catTag"><?php the_title(); ?></h2>
    
    			<div class="archiveCatTitle">
    				<h3>By Tag:</h3>
    			</div>
    			<div class="columns">
    				<ul id="tagsColumn">
    					<?php wp_tag_cloud(); ?>
    				</ul>
    			</div>
    
    			<div class="archiveCatTitle">
    				<h3>By Month:</h3>
    			</div>
    			<div class="columns">
    				<ul id="archTextMonth" class="columnItemArch">
    					<?php wp_get_archives('type=monthly&show_post_count=1'); ?>
    				</ul>
    			</div>
    
    			<div class="archiveCatTitle">
    				<h3>By Category:</h3>
    			</div>
    			<div class="columns">
    				<ul id="archTextMonth" class="columnItemArch">
    					<?php wp_list_categories('show_count=1&include=1,3,4,5,6&title_li=0&after= Entries'); ?>
    				</ul>
    			</div>
    
    			<div class="pagination"></div>
    
    		</div>
    
    	</div>
    
    <?php get_footer(); ?>

    Sebastien

    Sebastien,

    That archive template uses <?php wp_get_archives('type=monthly&show_post_count=1'); ?>. Try adding the argument to exclude categories to wp_get_archives(), like:

    <?php
    $eventsCatId = get_cat_ID( 'Events' );
    wp_get_archives('type=monthly&show_post_count=1&cat=-'.$eventsCatId );
    ?>

    That’s untested. If that function doesn’t take a category argument, you’ll need to use a loop instead, using arguments to query_posts() to produce the correct archive results.

    Justin

    Thread Starter Sébastien Thiroux

    (@mmarauder)

    Hi Justin,

    Sorry for taking so long,
    I did find a solution with a plugin: Advanced Category Excluder
    But this one caused more troubles than what it solved, so I’m going to try your solution even though I’m no php wizard.

    Thanks for your help

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: The Events Calendar] Don’t want calendar events to show in the blog posts’ is closed to new replies.