Forums

[resolved] using multiple template tags (6 posts)

  1. OzPoker
    Member
    Posted 1 year ago #

    Prolly a simple answer but I want to display a set of links from a category.

    I am using this code

    <?php $recent = new WP_Query("cat=6&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    <?php endwhile; ?>

    Now this works fine if all i want to display in the link name is the title.

    But the posts in question are in a category in the form :
    x category >> y sub-cat >> z sub-cat >> post

    I would like the link names to appear in the form:
    "z sub-cat name" "post title"
    not just "post title"

    Does anyone know how to code this properly ?

  2. OzPoker
    Member
    Posted 1 year ago #

    come on - this one would be easy for most of you guys

    please ?

  3. Kafkaesqui
    Moderator
    Posted 1 year ago #

    Patience, etc...

    Here's one problem on getting an answer:

    "But the posts in question are in a category in the form : x category >> y sub-cat >> z sub-cat >> post"

    Does this mean the post is assigned ONLY to the 'z sub-cat' category? Also, do you expect the category text to link to the category, or do you plan to make it just part of the post link?

  4. OzPoker
    Member
    Posted 1 year ago #

    lol - sorry

    yes post is assigned only to one category but htat category is a child category of a child category of a parent category.

    I just want to blend the category name with the title name to make the link name and that should link to the post only.

    Hope that is a little clearer.

    Thanks for your help.

  5. Kafkaesqui
    Moderator
    Posted 1 year ago #

    Simple way to accomplish this (assuming I have the request down pat) is to collect the category of the post through get_the_category() and print it out. get_the_category() will create an array as there is the possibility more than one category will exist for a post, but we can jump to the initial entry in that array here, as we can assume there's only one category on the post:

    <?php
    $recent = new WP_Query("cat=6&showposts=10"); while($recent->have_posts()) : $recent->the_post();
    $category = get_the_category();
    ?>
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php echo $category[0]->name; ?> <?php the_title(); ?></a>
    <?php endwhile; ?>
  6. OzPoker
    Member
    Posted 1 year ago #

    yup thats it - Thanks so much

    I was playing with the same commands all day but couldn't quite get the syntax right (my php sucks - lol )

    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic