• Resolved WP-Rasp

    (@wp-rasp)


    I’m doing it by the book and it’s still not showing right.

    I have 2 categories with a whole bunch of posts categorized. I want to exclude the posts from category id4 on my page and its not working.

    Am I closing the loop right?

    <?php
    
    /*
    
            Template Name: Product Category
    
    */
    
    ?>
    
    <?php get_header(); ?>
    
    <section class="row-fluid">
    
    <?php get_sidebar('category'); ?>
    
        <div class="span8">
            <ul class="breadcrumb">
              <li><a href="#">Home</a><span class="divider">>></span></li>
              <li><a href="#">Blog/Portfolio</a><span class="divider">>></span></li>
    
            </ul>
    
            <h1 class="text-center"><a href="#">Services</a></h1>
    
          <div class="row-fluid">
            <ul class="thumbnails">
    
         <?php // The WordPress Loop - customized with WP_Query
         $custom_query = new WP_Query('cat=-4'); // exclude
         while($custom_query->have_posts()) : $custom_query->the_post();
    
    <li class="span4">
    
       <article class="thumbnail clearfix">
    
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <p><?php the_excerpt(); ?> </p>
       <a href="#" class="btn btn-primary pull-right">Read More</a>
    
        </article>
    </li>
    
         endwhile;
    wp_reset_postdata(); // reset the query
         ?>
    </ul>
    
          </div> <!-- END OF first Row of thumbnail service -->
    
        </div>
    
    <?php get_sidebar( 'categorytwo' );?>
    
    </section>
    
    <?php get_footer(); ?>

    I want the li’s repeated as posts.

    I tried the regular loop and this is not working either..

    <div class="row-fluid">
    
            <ul class="thumbnails">
    
        <?php // The WordPress Loop - customized with query_posts
        query_posts('cat=-4'); // exclude categort(tag_ID = 4)
        if (have_posts()) : while (have_posts()) : the_post();
    
    <li class="span4">
    
       <article class="thumbnail clearfix">
    
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <p><?php the_excerpt(); ?> </p>
       <a href="#" class="btn btn-primary pull-right">Read More</a>
    
        </article>
    </li>
    
    endwhile; else:
    
        endif;
        ?>
         endwhile;
    wp_reset_postdata(); // reset the query
         ?>
    </ul>
    
          </div> <!-- END OF first Row of thumbnail service -->
Viewing 1 replies (of 1 total)
  • Thread Starter WP-Rasp

    (@wp-rasp)

    OK got it working

    <div class="row-fluid">
    
             <ul class="thumbnails">
             <?php
    
                $args = array('cat' => 4);
                $category_posts = new WP_Query($args);
    
                if($category_posts->have_posts()) :
                   while($category_posts->have_posts()) :
                      $category_posts->the_post();
             ?>
    <li class="span4">
    
       <article class="thumbnail clearfix">
    
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <p><?php the_excerpt(); ?>.</p>
       <a href="<?php the_permalink(); ?>" class="btn btn-primary pull-right">Read More</a>
    
        </article>
    
    </li>
    <?php
          endwhile;
       else:
    ?>
    
          Oops, there are no posts.
    
    <?php
       endif;
    ?>

    PHP is tricky I cant see the closing tags at all!

Viewing 1 replies (of 1 total)
  • The topic ‘WP query and query post loop not working’ is closed to new replies.