• Resolved warren_mlmlme

    (@warren_mlmlme)


    So this has been driving me nuts and its the last thing i need to finish my revamp of my site. the URL im working with is:
    http://www.mylovemylustmyeverything.com/magazine/issue-01/arts-and-culture
    Effectively, i have a series of pages that each contain a set number of posts. what i would like is for each page to only display posts from the category that it corresponds to. for example,i want the page arts and culture to only display posts with the arts and culture category selected.

    heres the code.

    <?php
    /*
    Template Name: PageOfPostsArts
    */
    
    get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    <h1>Art and Culture:: mlmlme.com</h1>
    <div id="fadeshow1" style="width: 700px; height: 300px; border: 1px solid black;">slideshow</div>
    
    <div id="mainContentTop">
    	Talk about current cultural movements with hyperlinks to relative articles.  talk about underground scenes and the prevailence in media and infiltration into pop culture.  talk of street art, graphiti and everything else from vynle toys to vector paintings, have it crammed full of relivant keywords.
    </div>  
    
    <?php
    $showposts = 7; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
       $args=array(
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    	<?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    
    				<div class="entry">
    					<?php the_excerpt (); ?> <a href="<?php the_permalink() ?>">Read More..</a>
    				</div>
    
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
        <a href="">Click Here for Arts and Culture Articles from Past Issues</a>
    
    	</div>
    
    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    <?php include (TEMPLATEPATH . '/footer.php'); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • spencersokol

    (@spencersokol)

    You can use the parameters from query_posts in your WP_Query call. There are a number of category parameters there. You can pass in the category by name.

    Codex: query_posts
    Codex: WP_Query

    Thread Starter warren_mlmlme

    (@warren_mlmlme)

    This looks like exactly what i need, but im kind of new to this. i get that query_posts('category_name=arts and culture');
    is what i need to use, but do i need to wrap it in code,and if so what, and where do i need to put it in my existing code?

    spencersokol

    (@spencersokol)

    All of the parameters you can use in query_posts can be used in your WP_Query object. So you can add it to your $args array.

    'category_name' => 'arts and culture'

    spencersokol

    (@spencersokol)

    One quick thing: when you include the sidebar and footer, you should make calls to get_sidebar() and get_footer(). I’m pretty sure (at least) get_footer() has additional functionality along side including the template file.

    Thread Starter warren_mlmlme

    (@warren_mlmlme)

    that was it exactly! thanks!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Page of posts with certian category’ is closed to new replies.