Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter effour

    (@effour)

    Anyone have any suggestions? I’m desperate! Thx ??

    Plugin is probably the easiest way: https://ryowebsite.com/?p=46

    Thread Starter effour

    (@effour)

    Thx, I think it may conflict with the excerpt_reloaded plugin i’m already using. Anyone elese?

    Thx!

    I’d be amazed if it conflicted, but I’m willing to learn and hear more details on that. ??

    I suppose you could check out The_Loop page and glance over this section: https://codex.www.ads-software.com/The_Loop#Exclude_Posts_From_Some_Category

    Thread Starter effour

    (@effour)

    The reason i’m hesitant to install the plugin in because i list a couple posts, then below I have a video, that only displays the last posted video https://www.vancityriders.com

    I just don’t want video posts to be listed in the first five…

    Anyone?

    Thread Starter effour

    (@effour)

    didn’t work, i installed the https://ryowebsite.com/?p=46 and it just broke the home page.

    All I want is it to exclude one catgegory from this loop…any more suggestions would be appreciated.

    thx.

    <?php
    $posts = get_posts('numberposts=4');
    foreach($posts as $post) :
    ?>

    <div class="post lastfive" id="post-<?php the_ID(); ?>">
    "><?php the_title(); ?>
    <br><br>
    <div class="bloginfo"><?php the_excerpt_reloaded(50, '<img> ', 'none', TRUE, 'Keep reading >>', FALSE, 2); ?></div>
    </div>

    <br><br>

    </div>

    <?php endforeach; ?>

    Thread Starter effour

    (@effour)

    anyone?

    I don’t know if it works with this tag, but with query_posts you can always use (‘showposts=7&cat=-3&offset=4’)
    which
    shows 7 posts
    excludes cat #3
    offsets the first 4 posts (shown in a different location)

    Thread Starter effour

    (@effour)

    Nope, didn’t work either. Surely there must be a way to exclude a category from this. Please, anyone. Thx!


    <?php
    $posts = get_posts('numberposts=4');
    foreach($posts as $post) :
    ?>

    <div class="post lastfive" id="post-<?php the_ID(); ?>">
    "><?php the_title(); ?>
    <br><br>
    <div class="bloginfo"><?php the_excerpt_reloaded(50, '<img> ', 'none', TRUE, 'Keep reading >>', FALSE, 2); ?></div>
    </div>

    <br><br>

    </div>

    <?php endforeach; ?>

    I know this one!

    Open your index.php file from you theme or default theme.

    About 1 quarter way down from the top, perhaps around line 9 or so if you haven’t hacked your theme template too much. up will see these lines:

    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">

    You will want to add the following line:

    <!-- Exclude post if in Category X and viewing from main page -->
    <?php if ( !(in_category('8') && is_home()) ) { ?>

    Immediately after this line:

    <?php while (have_posts()) : the_post(); ?>

    That says exclude this post if it’s in category X and if the user is viewing this from the homepage itself (that’s what I needed for one of my blogs, you can remove that homepage function if you don’t want posts to appear anywhere (keep in mind they will appear in you RSS feed though, I think, this just does what’s visible to the browser).

    Anyhoo, so you index.php will have something looking like this:

    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    <!-- Exclude post if in Category X and viewing from main page -->
    <?php if ( !(in_category('8') && is_home()) ) { ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">

    Then you need to close this IF statement down a ways, about line 27~ if you haven’t hacked up your theme. You should find this line:

    <?php endwhile; ?>

    Insert this line:

    <?php }; ?> <!-- Add this --->

    Just BEFORE the endwhile (little different). So the bottom or so of this page will look something similar to:

    <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    
    			</div>
    
    <?php }; ?> <!-- Add this --->
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.
    
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    That’s it, and it worked on 2.1, as I just applied it to another blog. Results may vary. The hack is not certified or sanctioned by the WordPress Gods. Apply at your own risk, I can’t help you if your blow up your blog, not because I wouldn’t want to help you fix it, it’s cause I wouldn’t know how. I know enough to be dangerous, hardly enough to be any good. So backup or something.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Exclude category’ is closed to new replies.