Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want get all categor and after that i want get 5 post per category. but my code not work! http://pastebin.com/vxDSGGZk

<?php
    $categories=get_categories('');
    foreach($categories as $category) { 
        echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
        echo '<p> Cat ID: '. $category->cat_ID. '</p>';

        // The Query
        $id_cat = $category->cat_ID;}
        $args = array(
            'cat' =>  $id_cat,
            'posts_per_page' => 5,
        );
        query_posts( $args );

        // The Loop
        while ( have_posts() ) : the_post();
            echo '<li>';
            the_title();
            echo '</li>';
        endwhile;
    }

    // Reset Query
    wp_reset_query();
?>

please help me! thanks! P/s:this is the first time i ask on here and i can't paste code in here. please check link pastebin.

share|improve this question
    
Please do not link code from external sources - always put everything one needs to understand your problem into your question. Thanks. –  kaiser Jul 25 '13 at 9:07
add comment

1 Answer 1

<?php
$categories=get_categories('');
foreach($categories as $category) { 
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Cat ID: '. $category->cat_ID. '</p>';

    // The Query
    $id_cat = $category->cat_ID;
    $args = array(
        'cat' =>  $id_cat,
        'showposts' => 5,
    );
    query_posts( $args );

    // The Loop
    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;
}

// Reset Query
wp_reset_query();
share|improve this answer
    
try above code , there was a error in loop. –  Vicky Jul 25 '13 at 10:05
    
Please add an explanation to your answer: why could that solve the problem? –  toscho Jul 25 '13 at 10:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.