Forums

[resolved] Showing posts for a certain catagory (5 posts)

  1. jimmytubbs
    Member
    Posted 2 years ago #

    I want to show a certain category in this code */ the code is displayed in a page so thats why i'm not sure if it has to be differen't */

    <?php
    if (is_page('21') ) {
    $cat = array(12);
    } elseif ( is_page('16') ) {
    $cat = array(32);
    } elseif ( is_page('28') ) {
    $cat = array(17);
    } else {
    $cat = '';
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       '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(); ?>">
    <div id=news><h2><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2></a></div>
    <?php the_excerpt(); ?>
     <h4><span id=news>Written by <?php the_author();?> at <?php the_time();?> <a>" rel="bookmark">Read More.... &nbsp; &nbsp <?php comments_number(); ?></a> </span></h4>
    <?php endwhile; else: ?>
    <div id=footerbg">
    			<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    		</div>
    
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
  2. jimmytubbs
    Member
    Posted 2 years ago #

    ..

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    That code is from http://codex.wordpress.org/Pages#A_Page_of_Posts

    But not sure what your question is?

  4. jimmytubbs
    Member
    Posted 2 years ago #

    I want to make that code show certain catagories

  5. MichaelH
    Volunteer
    Posted 2 years ago #

    Code says
    if page id is 21 show category 12
    if page id is 16 show category 32
    if page id is 28 show category 17

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.