Forums

Need help modifying a query to exclude category on home index (1 post)

  1. jeriksson
    Member
    Posted 2 years ago #

    Hi,

    I'm using a custom theme and i'm not a php coder, i can't figure out how to modify the following query to not display a post if it is in category of choice.

    <?php if (have_posts()) : ?>
    
    		<!-- First Post -->
      	<?php $top_query = new WP_Query('showposts=1'); ?>
      	<?php while($top_query->have_posts()) : $top_query->the_post(); $first_post = $post->ID; ?>
    			<?php
    			$url 	= $_SERVER['REQUEST_URI'];
    			$find = "page";
    			$pos 	= strpos($url, $find);
    			if ( $pos == false ) : ?>
    			<?php if(!$stickied or is_sticky()) $stickied = true; ?>
    			<div class="post top" id="post-<?php the_ID(); ?>">
    			<h2 class="first"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'chaoticsoul'), get_the_title()); ?>"><?php the_title(); ?></a></h2>
    				•<?php the_time(get_option("date_format")); ?>  • <?php comments_popup_link(__('No Comments', 'chaoticsoul'), __('1 Comment', 'chaoticsoul'), __('% Comments', 'chaoticsoul')); ?> <?php edit_post_link(__('Edit', 'chaoticsoul'), '(', ')'); ?>
    				<div class="entry">
    					<?php the_content("<span class=\"continue\">" . __('Continue reading', 'chaoticsoul') . " '" . the_title('', '', false) . "'</span>"); ?>
    
    					<p class="postmetadata"><?php printf(__('Posted in %s', 'chaoticsoul'), get_the_category_list(', ')); ?>
    						<?php print get_the_term_list( $post->ID, 'post_tag', '<br />' . __( 'Tags' ) . ': ', ', ', ''); ?>
    					</p>
    				</div>
    			</div>
    			<?php endif; ?>
    		<?php endwhile; ?>
    
    		<!-- Next few posts -->
    		<?php 
    
    		while(have_posts()) : the_post(); if(!($first_post == $post->ID) && !is_sticky()) : ?>

    I've used this code

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=-261&paged=$page"); ?>

    to block out categories but it only works for the posts second to the first one.

    Anyone who who knows some good php should be able to figure this out rather quickly? I'm thinking i need something on the code right here:

    <?php $top_query = new WP_Query('showposts=1'); ?>
      	<?php while($top_query->have_posts()) : $top_query->the_post(); $first_post = $post->ID; ?>

    Thanks a lot for any help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.