• Resolved AdamJWL

    (@adamjwl)


    I have scoured the posts already available but I still can’t seem to get it. I bet some of you are fed up of seeing the same old stuff!

    Im running a travel website, https://www.travelvows.com. I have a page for reviews, a page for guides, and now I have just created a new page for a personal blog part. Im creating a new template (identical to the one I am using under ‘Guides’).

    On my dashboard, a ‘Post’ goes onto my ‘guides’ page, and ‘Reviews’ goes onto my ‘Reviews’ page. I am attempting for the ‘Post’ category ‘Blog’ to appear solely on my ‘Blog’ page, and not on my ‘Guides’ page.

    If you haven’t glossed over yet, we’ll talk about code.

    <?php
    
    /*
    
    Template Name: Blog
    
    */
    
    ?>
    
    <?php get_header(); global $colabs_options; ?>
    
    <div id="stories-map"class="map-destinations columns col11"></div><!-- .map-destinations -->
    
    <?php  echo setMap( array(
    
    	'el' => 'stories-map', 
    
    	'posttype' => 'post'
    
    	)
    
    );  ?>	 
    
    <div class="main columns col11">
    
    	<div class="col-stories columns col11 fl">
    
            <h2 class="ribbon"><?php _e('Blog','colabsthemes');?></h2>
    
    		<?php $query_posts = new WP_query('post_type=post&paged='.$paged);?>
    
    		<?php if($query_posts->have_posts()):?>
    
            <ul class="post-list">
    
    			<?php while ( $query_posts->have_posts() ) : $query_posts->the_post(); ?>
    
                    <li class="posting">
    
    					<?php colabs_image(array());?> 
    
    					<h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
    
    					<span class="bigred"><?php the_category(' ,');?><?php the_tags(' // ', ', ', '');?></span>				
    
    					<br/><?php colabs_custom_excerpt();?>
    
    					<div class="more"><a href="<?php the_permalink();?>"><?php _e('read more','colabsthemes');?></a></div>
    
    				</li>
    
                <?php endwhile; ?>
    
    		</ul>
    
    		<?php colabs_pagination('', $query_posts);?><!-- .pagination -->
    
    		<?php endif;?>		
    
        </div>
    
        <?php //get_sidebar();?>
    
    </div>
    
    <?php get_footer(); ?>

    The above code is for my new template, which I wish to exclude all categories apart from the ID=2 (blog). I have seen some examples and tutorials online but I am not sure where to put the extra code get_post.

    <?php
    
    /*
    
    Template Name: Stories
    
    */
    
    ?>
    
    <?php get_header(); global $colabs_options; ?>
    
    <div id="stories-map"class="map-destinations columns col11"></div><!-- .map-destinations -->
    
    <?php  echo setMap( array(
    
    	'el' => 'stories-map', 
    
    	'posttype' => 'post'
    
    	)
    
    );  ?>	 
    
    <div class="main columns col11">
    
    	<div class="col-stories columns col11 fl">
    
            <h2 class="ribbon"><?php _e('Guides','colabsthemes');?></h2>
    
    		<?php $query_posts = new WP_query('post_type=post&paged='.$paged);?>
    
    		<?php if($query_posts->have_posts()):?>
    
            <ul class="post-list">
    
    			<?php while ( $query_posts->have_posts() ) : $query_posts->the_post(); ?>
    
                    <li class="posting">
    
    					<?php colabs_image(array());?> 
    
    					<h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
    
    					<span class="bigred"><?php the_category(' ,');?><?php the_tags(' // ', ', ', '');?></span>				
    
    					<br/><?php colabs_custom_excerpt();?>
    
    					<div class="more"><a href="<?php the_permalink();?>"><?php _e('read more','colabsthemes');?></a></div>
    
    				</li>
    
                <?php endwhile; ?>
    
    		</ul>
    
    		<?php colabs_pagination('', $query_posts);?><!-- .pagination -->
    
    		<?php endif;?>		
    
        </div>
    
        <?php //get_sidebar();?>
    
    </div>
    
    <?php get_footer(); ?>

    This is the code I wish to excluse JUST ID=2 (blog) and allow all others to go through.

    If anyone could help me and allow me to sort this problem I would be greatly appreciative.

    Thanks for reading!

    Adam

Viewing 4 replies - 1 through 4 (of 4 total)
  • In the first set of code change
    <?php $query_posts = new WP_query('post_type=post&paged='.$paged);?>

    to
    <?php $query_posts = new WP_Query('post_type=post&cat=2paged=' . $paged); ?>

    Alternatively

    <?php $query_posts = new WP_Query( array(
      'post_type' => 'post',
      'paged'       => $paged,
      'cat'            => 2
    ) );

    Do the same for the second block of code but change ‘cat’ from 2 to -2

    Thread Starter AdamJWL

    (@adamjwl)

    Thanks for the reply,

    It’s probably me doing it wrong, but your first suggestion

    – eliminates all posts from the ‘Blog’ page, and fails to eliminate any from the ‘Guides page’

    The second suggestion;

    – leaves me with a completely white screen.

    Do you know what I am doing wrong?

    Thread Starter AdamJWL

    (@adamjwl)

    Just checking, I have the correct ID, yes? The URL for the ‘blog’ category is

    edit&taxonomy=category&tag_ID=2&post_type=post

    I am assuming ID=2 means 2.

    Thread Starter AdamJWL

    (@adamjwl)

    Solved, thank you so much Nathan,

    My ID was 2&.

    Very much appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding Posts (again!)’ is closed to new replies.