Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Displaying custom post type titles in WP?

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #30136

    I have been looking and looking and just cannot find an answer nor figure this out. I’ve learned a lot from here and Digging Into WordPress so I thought this was a good place to ask. I’ve already asked this on 2 other forums with no answers.

    So basically I want to do something in the vein of what is in this screenshot from this post Justin Tadlock’s site. I want my custom post type titles to automatically display with that individual post’s title. If you look at the screenshot they’re in grey. So for example it’d say “Movie” before a post type of “Movie” followed by the movie’s name and “Book” before a post type of “Book”, etc.

    Could anyone give me some insight into this?

    #80727
    TheDoc
    Member

    Holy hell this took a lot of time to find!

    
    echo $post_type->label ; ?>
    #80728
    Hayley
    Member

    Interesting question. I’ve never done this before, but I had to figure out a way. I don’t know if this is the right way, but it works for me:
    I used get_post_type()


    echo $post_type; ?> //this outputs the post type name, e.g. 'movie'
    //this is the title of the post

    This outputs the post type in lowercase, so I applied a class and used CSS text-transform to capitalize.
    I couldn’t find a tag that output the name or label that was already capitalized.

    #80729
    Hayley
    Member

    Oooh…nice Doc. I didn’t see yours before I posted :-)

    #80662

    Thanks I’d been searching for this for a while!

    #80637

    I had posted this same question over in Justin Tadlock’s forums before I posted here and he just responded with a different solution that I find a little more customizable. His code is this:

    
    
    $type = get_post_type();

    if ( 'movie' == $type )
    echo 'Movie: ';
    elseif ( 'book' == $type )
    echo 'Book: ';

    ?>

    So you just keep adding elseif’s for you’re various types and what you want them to say, so if I want a movie post type to output Film instead of Movie or maybe I want it to say Movie Review it will do it. This also stops regular posts from displaying with “post” before them.

    I’ve been trying to figure this out on my own for so long and within 24 hours got 3 solutions. Wow. Well that’s one hurdle.

    #80623
    TheDoc
    Member

    Hmmmm. His solution makes sense, but if you update the Label this just means you’ll need to update it in two places instead of one.

    Furthermore, if you are going to use that code in multiple places in the site, you’ll be updating a single word even more – which of course takes away from the wonderful dynamicness of the whole system.

    #127347

    Haley and The Doc, thank you for sharing your code(s). I have been looking all day for this solution.

    #182602
    lxm7
    Participant

    4 years later but @TheDoc, I’d been looking for this before for ages too. I was switching between get_post_type_object and get_post_type and attempting to find the right property and echo it. It wouldn’t have occured to wrap one in the other. Cheers for posting this!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Back End’ is closed to new topics and replies.