• Resolved lqz

    (@lqz)


    I’m trying to make WordPress into my idea of what a writer’s CMS should be. I think my wants are modest but so are my coding abilities. I believe I have all the pieces I need to do what I want. I just don’t know how to put them together.

    What I want is a Page that will list the titles in a given category automatically. Right now I use the following but have to make a new Page template for each new story/category I start.

    <?php
    $photog_posts = new WP_Query(‘category_name=el&order=asc&showposts=-1’); while($photog_posts->have_posts()) : $photog_posts->the_post();
    ?>

    <li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permalink to <?php the_title(); ?>”><?php the_title(); ?</a>
    </li>
    <?php endwhile; ?>

    </ul>

    I have a category called “Eight Lines” I made its slug “el”, when I set up a Page for it I made its slug “el” also. This bite of code <?php echo $post->post_name; > gives me the Page slug. However putting the code in like so, (‘category_name=<?php echo $post->post_name; ?>&order=asc&showposts=-1’);, is not working. I have tried different things but I don’t know what to do.

    So how do I get the out put of <?php echo $post->post_name; ?> to where I want it on the other side of category_name=.

    I use a different bit of code for the sidebar and tried to fit it in there but again no luck.

    <?php
    $cat = get_the_category();
    $cat = $cat[0];
    $posts = get_posts(“category=” . $cat->cat_ID . “&order=asc&numberposts=10000”);
    if( $posts ) :
    ?>

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li><id=”post-<?php the_ID(); ?>”>
    <a href=”<?php the_permalink() ?>” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    <?php endif; ?>

    I will appreciate any help anyone can give me. Also many thanks to the people that posted the code I am using now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Kafkaesqui

    (@kafkaesqui)

    RE: Page listing the titles in a given category

    Where is the benefit to using a Page for this over the normal category query and a Category Template that only displays the titles?

    RE: Page slug

    The syntax should be:

    WP_Query("category_name=$post->post_name&order=asc&showposts=-1");

    PHP info: Do not nest <?php tags. Do not echo variables passed to a function. If mixing text strings and variables, use double-quotes; single quotes force a var to be interpreted literally (i.e. ‘$post->post_name’ and not ‘el’).

    RE: $cat = get_the_category()

    The function get_the_category(), when no argument is provided (i.e. the category ID), will attempt to collect the category data from the post loop. Using it outside The Loop (which a sidebar typically is) will lead to inconsistent results. But providing it a category ID is redundant here, since all your code does is pass the ID to get_posts().

    Thread Starter lqz

    (@lqz)

    RE: Page listing the titles in a given category

    I use the Category Template system to list all the post in a category.
    I did think of using Category Template for this. But then I would have the problem of trying to automatically list all the post in a category on a Page.

    RE: Page slug

    That didn’t work for me. I typed it in then cut and pasted it in and still no go. I don’t even get an error, it just doesn’t list anything.

    RE: $cat = get_the_category()

    Given that I can’t set a Page’s category in the Admin panel. Is there a way to set it in The Loop.

    Also why can’t I do $cat = $post->post_name or something like that to set the category for the rest of the code.

    Thanks for your help.

    Thread Starter lqz

    (@lqz)

    RE: Page slug

    I screwed up and the code you gave was good. I had code above it that messed things up.

    RE: $cat = get_the_category()

    I would still like an answer as to if I could set the category from in The Loop. Or if I could use $cat = $post->post_name, $cat_ID = $post->post_name or something else to set the category for the second bit of code.

    Kafkaesqui

    (@kafkaesqui)

    I would still like an answer as to if I could set the category from in The Loop.

    When you’re on a Page there’s only one category to pull from The Loop: the default category (Pages are assigned to it for internal purposes only). So if that’s where you’re expecting to display it in your sidebar, it will be of no use to you. When on a single post, however, you could initialize the post query:

    <?php
    global $wp_query;
    $post = $wp_query->post;

    From there try get_the_category(), etc.

    Thread Starter lqz

    (@lqz)

    “So if that’s where you’re expecting to display it in your sidebar”

    I’m not trying to display this in the sidebar, I want it in the body like on this page.

    The following didn’t work for me, so I was wondering if I could do something like it.

    {

    <?php
    $cat = $post->post_name
    $cat = $cat[0];
    $posts = get_posts(“category=” . $cat->cat_ID . “&order=asc&numberposts=10000”);
    if( $posts ) :
    ?>
    }

    I’m not sure why I can’t use that or $cat_ID = $post->post_name in place of $cat = get_the_category() to set the category for the code.

    Thanks for your help again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP CMS-help me put the pieces together.’ is closed to new replies.