• Heya guys, I need help with two quick things:

    First, how could I find out if there are any tags for a post? I need to check if there are tags, and do one piece of code (HTML / CSS), and if there aren’t any, do another few lines code.
    I can’t find a function like that in codex :/

    Second, how could I get category ID’s for a post?
    I’m getting my posts with
    $the_query = new WP_Query (...), and writing them out with
    while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
    I need to get category ID’s for every post and count how many posts from certain categories are there on the frontpage.
    I would then use that to determine the offset for displaying more posts from the categories (one category at a time).

    To make things short – I want to display last 10 posts (with thumbnail, excerpt etc) on the front page, and below that display last 5 posts for every category with titles and small thumb only (excluding ones already displayed).

Viewing 4 replies - 1 through 4 (of 4 total)
  • I haven’t done the 2nd, but I’ve done the 1st. To get post tags, I’ve used:

    $my_variable = get_the_tags($put_postid_here) ;

    Check out the codex entry.

    It’s null if there are no tags for that post, otherwise it’s an array of objects, and you can loop through and parse out the tag names.

    HTH,

    -WC

    Thread Starter kreso777

    (@kreso777)

    Excellent, thank you!
    Didn’t see that in Codex :/

    If anyone knows how to do the second one, I’d appreciate the help 🙂

    Sure, no problem. There are a few tags-related functions, and that one was the best for my needs.

    Regarding your categoryIDs need… I have a feeling there are some helper functions for that sort of thing, too. You may not even need to address object properties or methods if you don’t want.

    OT: Say, I’m kinda new to the forums here. How are people here typically keeping themselves notified of updates to favorite threads? RSS -> feed readers, then checking their readers? RSS -> FeedBurner -> email updates? Just adding and checking their Favorites here? I’m doing it the old fashion way: dragging shortcut-icons to my desktop and manually checking every so often. I love forums with email notifications. Maybe I should use FeedBurner.

    -WC

    Thread Starter kreso777

    (@kreso777)

    Yeah, it did the job for me too 🙂

    Regarding the category id, I finnaly found this:
    http://www.web-templates.nu/2008/08/29/get-category-id-alternative/
    I think this should do the trick, I’ll try that now.

    Regarding OT: I suppose RSS would be the way to go, it seems there are no mail notifications. I just left a tab open and refreshed once in a while 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting category ID and checking if tags exist’ is closed to new replies.