• I guess I’ve been away from WP for too long, and I’m lost. Yes, I’ve read a bunch of posts and docs….I’m still lost.

    I want a Page that will display links to all the posts in a particular category. I’ve created a template for the page, but apparently I have the wrong code in the template. What should it be?

    If there are instructions for this somewhere that I’m just totally missing, please point me in the right direction.

    Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • I want a Page that will display links to all the posts in a particular category

    The only problem is the “Page”. Use a category template instead that does that automatically.

    Thread Starter kalico

    (@kalico)

    Ok, after reading your posts I realized I’ve done this before. Told ya I’ve been away too long! I have tweaked my code from the other Page, and it’s working — but I have one other thing I want to do, and I’m not sure how to get there.

    <?php
    $results = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent FROM ".$wpdb->categories." WHERE cat_ID = '29' ORDER BY cat_ID ");
    ?>

    <?php foreach($results as $cat){ ?>
    <a href="<?php echo get_category_link($cat->cat_ID); ?>">
    <?php echo $cat->cat_name; ?></a>

    <?php query_posts('category_name='. $cat->cat_name . '&showposts=-1&order=ASC'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>

    <? }?>
    This ends up something like this:

    PARENT_CATEGORY_NAME (link)
    * Linkified Post Title
    * Linkified Post Title
    * Linkified Post Title
    * Linkified Post Title

    Very nice. I’m almost there.

    Now what I want it to do is display the child categories above their respective posts. So the posts are sorted under the child categories to which they belong. (It’s ignoring child/parent relationships, and just displaying the parent category name.) Does that make sense?

    Any help would be greatly appreciated.

    PS I know the code isn’t very clean. I didn’t write it, I copied it, and all attempts to clean it up failed, so I went back to what worked. It wasn’t broke, so……

    And please, would someone tell me how to post code in this forum so I don’t have to edit a thousand times? Backticks only seem to work around single lines of code, and code tags don’t seem to work the way I expect them to. Thanks!!

    If there are NO blank lines in the code – backticks work 🙂

    Thread Starter kalico

    (@kalico)

    Thanks moshu. What if there are blank lines? What is the correct format for the “code” tag? I assume that would work if there are blank lines (there must be a way….having no blanks in a block of code that long would be hard to read).

    Anyone know what my code needs to accomplish my goal?

    TIA 🙂

    Don’t post long code 🙂 – for long code use a pastebin service. You don’t use the “code” tag here in the forum. Just a backtick before you start the code and another one at the end.

    Thread Starter kalico

    (@kalico)

    Hmmm…. well for some funny reason, they have the “code” tag listed in “allowed tags” right below this box as I type….lol 🙂 Thanks moshu, for the tips. 🙂

    OK now….. back to the real problem. I would really like my code to generate the sub-category title, and group the posts by subcategory — not just the parent category title and one big list. Does anyone know how to do that?

    I’m not even sure where to start looking for clues. Any help would be appreciated.

    TIA 🙂

    I have tried something similar for a long time but re-grouping posts from a category based on other categories never worked for me 🙁

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Category links on Page’ is closed to new replies.