• Hello,

    I’m attempting to convert my Textpattern blog over to WordPress (hurray, a convert!). WordPress’ tag structure is very different from Textpattern’s, however, and I’m having some trouble.

    I’d like to create a menu of entries within a category. Is there a tag that will list headlines within a specific category?

    Thanks,
    theturninggate

Viewing 2 replies - 1 through 2 (of 2 total)
  • the get_posts tag this is dependent on knowing the category ID and calling each one individually.

    you can alternatively make a function and add it to your functions.php in your theme like so:

    /* list categories with posts by tugbucket.net */
    function cat_and_posts(){
    foreach (get_categories(array('hide_empty'=>true)) as $category)
    {
    $catid = $category->cat_ID;
    global $post;
    $myposts = get_posts('category='.$catid);
    echo '<li>' . $category->cat_name . "\n";
    echo '<ul>' . "\n";
    foreach($myposts as $post) {
    echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>' . "\n";
    }
    echo '</ul>' . "\n";
    echo '</li>' . "\n";
    }
    };
    /* end */
    1. So we get all the categories that are not empty.
    2. We make a variable that is each categories ID.
    3. Set the posts global.
    4. Set a variable for the get_posts function where the category is our first variable.
    5. Then start building a list where the first is the category name.
    6. Then nest a list inside that listing each post in that category.
    7. Finally close out all the lists in order.

    Call it in your template like so:

    <ul>
    <?php cat_and_posts(); ?>
    </ul>

    It will output something like this:

    • Category Name
    • Post 1
    • Post 2
    • Category Name
    • Post 1
    • Post 2
    Thread Starter theturninggate

    (@theturninggate)

    Thanks, tugbucket. That’s working nicely.

    Is it possible, though, to specify a particular category or categories using a list of category names?

    Also, I changed the output code some:

    /* list categories with posts by tugbucket.net */
    function cat_and_posts(){
    foreach (get_categories(array('hide_empty'=>true)) as $category)
    {
    $catid = $category->cat_ID;
    global $post;
    $myposts = get_posts('category='.$catid);
    echo '<dt>' . $category->cat_name . '</dt>' . "\n";
    
    foreach($myposts as $post) {
    echo '<dd><a href="' . get_permalink() . '">' . get_the_title() . '</a></dd>' . "\n";
    }
    }
    };
    /* end */
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display list of headlines within a specific category’ is closed to new replies.