开发者

Page Not Pulling From Correct Category?

I need the page below to pull from a certain category. I'm not sure how to do it...in other words when the page is pulled up it will pull all the posts from one category and that category only.

Not sure what to add or where to add it? The category is "For Sale"

http://ampmproperties.com/for-lease-orange-county

<?php
/**
 *  Template Name: For Sale
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

    <div id="container">
    <div class="left_sirebar">
        <?php get_sidebar(); ?>
    </div>
        <div id="co开发者_如何学运维ntent" role="main">
            <?php $args = array(  'posts_per_page' => 3 );
                        $loop = new WP_Query( $args );
                        while ( $loop->have_posts() ) : $loop->the_post();

                        if ($count==1)
                        {
                            echo "<tr>";
                        }

                       echo '<td><div class="For Sale">';
                        echo '<div class="heading_div"><h2 class="entry-title">';
                            the_title();
                            echo '</div></h2>';
                        echo '<div class="entry-content">';

                            echo '<div class="desc">';
                            the_excerpt();
                        echo '</div>';
                    echo '</div></div></td>';

                        if($count==$number_of_columns)
                        {
                        echo "</tr>"; 
                        $count=0;
                        }   
                        $count++;

                        endwhile;
                    ?>

        </div><!-- #content -->
    </div><!-- #container -->


You need to add the category name to your arguments array:

$args = array('posts_per_page' => 3, 'category_name' => 'For Sale');

WordPress' documentation is quite good - whenever you need help with a function like WP_Query, look it up. Your solution was right there in the documentation: All Posts in a Category.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜