WordPress.org

Ready to get started?Download WordPress

Forums

Display all posts from one category (3 posts)

  1. michellecantin
    Member
    Posted 1 year ago #

    Hi,

    I am trying to put all of my posts from the "tutorial" category on a page. I have used this, but it does not work :

    <?php
    $catPost = get_posts(get_cat_ID("3")); //change this
       foreach ($catPost as $post) : setup_postdata($post); ?>
    
    <h1><a>"><?php the_title(); ?></a></h1>
        <?php the_excerpt(); ?> 
    
    <p class="postinfo">Written by: <?php the_author_posts_link(); ?>
    Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
    Categories: <?php the_category(', '); ?></p>
    <hr />
    <?php  endforeach;?>

    It also shows posts from other categories: http://mybluebox.dearestdesigns.com/?cat=3

    I previously tried this one, but it says error on line 17.

    <?php
    // The Query
    query_posts( array ( 'category_name' => 'tutorials', 'posts_per_page' => -1 ) );
    ?>
    
        <?php
    // The Loop
    while ( have_posts() ) : the_post();
    	echo '<h1>';
    	the_title();
    	echo '</h1>';
    	the_excerpt();
    	echo ' <p class="postinfo">Written by: ';
    	the_author_posts_link();
    	echo 'Posted on '
    	the_date();
    	echo 'Categories: '
    	the_category(', ');
    	echo '</p>'
    	endwhile; ?>
    
    	  <?php
    
    	  // Reset Query
    	  wp_reset_query();
    
    	  ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Function_Reference/query_posts

    http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

    the $catPost syntax is plainly wrong; try:

    $catPost = get_posts('cat=3&posts_per_page=-1'); //change this

    the 'error in line 17' is probably caused by a missing semicolon, here:

    echo '</p>';
  3. michellecantin
    Member
    Posted 1 year ago #

    Thank you for your help! Both worked :)

Topic Closed

This topic has been closed to new replies.

About this Topic