• I would like to be able to show a list of posts (basically an archive) by category. I would like to run sections of my site with this method.

    ex- you click on the music section of the site and it brings you to a simple index file that lists all the posts in the music category.

    I cant seem to find anything along those lines from the codex on archives or categories, and havent found a plugin…

    something like what goes on here:
    https://codex.www.ads-software.com/Template_Tags/list_cats

    but in “plain speak” mine would be to list posts by category.

    or something like:
    https://codex.www.ads-software.com/Template_Tags/get_archives

    plain speak- get archives post by post, BUT with a single category

    any help would be appreciated…

    tia
    l??k

Viewing 15 replies - 1 through 15 (of 33 total)
  • Thread Starter lokjah

    (@lokjah)

    <?php $my_query = new WP_Query('category_name=special_cat&showposts=10'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    // Do stuff.
    <?php endwhile; ?>

    this one? if so, im not quite sure how to use it. do I just need this loop by itself?

    and “category_name” how would I use the category ID?

    thanks alphaiode

    Thread Starter lokjah

    (@lokjah)

    ok ive got something like this so far, am I doing it right?

    <?php $my_query = new WP_Query('category_id=1&showposts=10'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <h2 id="post-<?php the_ID(); ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <?php endwhile; ?>

    Thread Starter lokjah

    (@lokjah)

    this seems to be working, although it doesnt just list category_id=1 posts, it lists others as well…..

    If you want to pass category id, use keyword cat
    If you want to pass category name, use keyword category_name
    There is no category_id

    Thread Starter lokjah

    (@lokjah)

    cat=1
    returns an error:

    WordPress database error: [Not unique table/alias: ‘mainwp_post2cat’]
    SELECT DISTINCT * FROM mainwp_posts LEFT JOIN mainwp_post2cat ON (mainwp_posts.ID = mainwp_post2cat.post_id) LEFT JOIN mainwp_post2cat ON (mainwp_posts.ID = mainwp_post2cat.post_id) WHERE 1=1 AND (category_id = 1) AND post_date_gmt <= ‘2005-05-05 02:02:59’ AND (post_status = “publish”) AND (category_id = 1 OR category_id = 5 OR category_id = 6) GROUP BY mainwp_posts.ID ORDER BY post_date DESC LIMIT 0, 999

    Thread Starter lokjah

    (@lokjah)

    also interesting is that bit:

    AND (category_id = 1 OR category_id = 5 OR category_id = 6)

    those are the very categories that were showing up in addition to category 1

    I’m lost right now. Is passing category_name working for you?

    Thread Starter lokjah

    (@lokjah)

    no that throws the same error as using “cat”

    the one that works sort of is the one i posted above:

    <?php $my_query = new WP_Query('category_id=1&showposts=10'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <h2 id="post-<?php the_ID(); ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <?php endwhile; ?>

    that works but doesnt show just category 1 posts, it shows 1, 5 and 6 like the error message states above.. so that is coming somewhere from the original example you pointed me to

    Do, instead, example 2 in that CODEX link. In this example, the regular loop will be overwritten, so make sure you call the custom loop after the regular loop (if any).

    Thread Starter lokjah

    (@lokjah)

    ok that one works!

    now where its showposts=10

    is there a way to substitute the # (10 in this case) with something like “all” or will I need to use some exorbidant # like 999 ?

    You could pass posts_per_page=-1
    Don’t forget the ampersand symbol (&) between parameters.

    Thread Starter lokjah

    (@lokjah)

    sweet, last thing is there anyway that I can add multiple categories? I have a news link that i want to show posts from a few categories…

    <?php query_posts('cat=1,4,5&showposts=3'); ?>

    is that written right?

    separated by a comma or a whitespace, I believe

    Thread Starter lokjah

    (@lokjah)

    thanks for all the help alphaoide ??

Viewing 15 replies - 1 through 15 (of 33 total)
  • The topic ‘List post titles by category?’ is closed to new replies.