• Hi, I found a bit of code via the search on the forums here, but its not quite how I hoped. Im using this:

    <?php
    $category = get_the_category();
    if($category[0]){
    echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
    }
    ?>

    Which only displays the first category.

    Im hoping some php/wordpress wizard could help me do the following:
    1) Display all categories, apart from one (This because the theme requires all posts to have part of feature (so they appear on the home page).
    2) Format them like [Movies}[TV] etc

    I did try the codex thing, struggled to get this far would really appreciate some advice!
    Thanks in advance

Viewing 12 replies - 16 through 27 (of 27 total)
  • Thread Starter fracmo2000

    (@fracmo2000)

    You are a php genius man! I wish I could do that. Ok, I an idiot, but do I just change the following?
    <?php if (is_category( array( 322,328,459,460 ) ))

    Nothing else? Im getting the id from

    wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=328&post_type=post

    Thanks for the style tip, I think I will leave it for the time being…I struggling already haha! Cheers deepbevel

    Yes, I think I can write about 12 characters in php. On a good day. Thank you very much.

    just include the id’s you want to ..include. To find the id’s go to the category edit page (posts/categories). Click the category name and when on the edit page, look up in the url, you may have to click it to see it all. You’ll see ID=”some-number”.

    Thread Starter fracmo2000

    (@fracmo2000)

    I have been trying to get it working before I posted back. Installed reveal id plugin just to make sure I was using the right ones. When I use it, it turns up blank. I can only get it to work if I put a ! before the is_category…which i know isnt what I want (makes it if not?)

    Thought we had it sussed there, must be something weird with my setup.

    I just tested again, works like it should in the_meta div in twentyten single.php. If it’s backwards for you, I can’t explain it, but just use categories you want to exclude, the others should show up.

    Keep in mind your posts are output on the blog page (loop.php), and category and archive pages (archives.php) as well as single post view (single.php) You have to do this where ever you want it to be output. Are you looking at the right template?

    Thread Starter fracmo2000

    (@fracmo2000)

    i really appreciate you helping me deepbevel, but I reverted back to your original bit of code

    <?php
    // For each of the categories, create them as category variables
    foreach((get_the_category()) as $category) {
        // If the category is NOT the cat_name (category name) then echo some stuff
        // So grab all... except where they match cat_name (exclude basically)
        if ($category->cat_name != 'Test Category One') {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
    }
    }
    ?>

    I removed the video (parent) category and moved all the others up a level…which means I just need to exclude Featured (which now works ?? )

    I would like to some how rename the categories from Movies -> [Movies] [TV] [Music] etc…so will get on to that.

    Cheers again man, all the best ??

    Thread Starter fracmo2000

    (@fracmo2000)

    Hey Deepbevel, if you ever read this…I found out how to style the cat titles:

    echo ‘term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>[’ . $category->name.’] ‘;
    //added [ = [ and ] = ]

    It wraps the title inside the square brackets [ ]

    Awesome

    I always read these. But I never understood for sure what you meant by:

    Can the method you posted (thats works!!!) be easily stylized? I was hoping to go for [Movies][TV][Music] etc or something to that effect.

    Are you just talking about adding the “View all posts in” to the links??

    Thread Starter fracmo2000

    (@fracmo2000)

    prob easier if I could show you, I will try this:

    Post Tile
    Image
    Fail Funny Ouch

    to this

    Post Tile
    Image
    [Fail] [Funny] [Ouch]

    I just didnt want plain txt or little icons to differentiate between categries, as I dont usually like that myself. The cat titles are small and seemed to run into each other, just looked like a bundle or words together. I also dont have a post description (setup magazine style 6 columns by 4 rows), so my thinking was to give the user a little info on the post. Less is more kinda thing.

    I dont knwow how to pm, unsure about posting my site up as its not finished yet.

    Thread Starter fracmo2000

    (@fracmo2000)

    Almost forgot, thanks for checking back and for the help with the code…really appreciated.

    One more thing and Im ready to go live!

    I don’t think the forum has a pm method, if you want to contact me and share a link I’d take a look.
    the link is my only personal wp site, for my picture framing service, the reason I learned wp. Since I started it about 2 years ago I’ve gotten so many requests for sites that I’ve never had time finished it!

    Thread Starter fracmo2000

    (@fracmo2000)

    In demand haha. Ok, I will send it over ??

    haha, yeah don’t get the wrong idea. 50% of my time, 2% of my income. I flew in here blind and am only just begining to see. Everything I can do I learned here. This is my school, I’m student and teacher, often at the same time.

Viewing 12 replies - 16 through 27 (of 27 total)
  • The topic ‘Display certain post categories under post title’ is closed to new replies.