• Resolved OrignalCeiling

    (@abandonedar)


    Hi All, I have to post types (Core posts & ‘Awards’) when you go to an archive page it displays all post types regardless if core or ‘Awards’ which I want! BUT What I would like to do is add a line before each post type ‘Awards’

    For intance: if the ‘Awards’ post title is “Kansas Firefighters Museum” instead I’d like it to say “Awards: Kansas Firefighters Museum”

    I’m no wordpress expert, but logically the code would look *somthing* like this.

    <?php if ( get_post_type() === 'awards' ) { 
        Awards: 
    } ?> } else { Posts: <?php the_title(); ?>

    I hope this is making sense.

    • This topic was modified 2 years, 1 month ago by t-p. Reason: Moved to Fixing WordPress from Developing with WordPress

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Alan Fuller

    (@alanfuller)

    I assume you want to modify the title in archives? e.g. Posts: Title , Awards Title

    So logically

    filter the title
        if not archive page
           return  the title unchanged
         if an awards post
              return title as Awards: title
         return  title as Posts: title
    

    Is that enough to get you on the right track?

    Post your revised code to check

    Thread Starter OrignalCeiling

    (@abandonedar)

    Thank you for the reply, this sounds what I am looking for, but I do not know how to turn that into the right code… Any further code you can provide? Thank you in advance! I think this will do the trick.

    Alan Fuller

    (@alanfuller)

    Thread Starter OrignalCeiling

    (@abandonedar)

    I figured out a simpler way to do it!

    add_action ('the_title' , 'endangered', 10, 2);
    function endangered($title, $id) {
      return 'post' === get_post_type($id) ? '<div>Endangered:</div> ' . $title : $title;
    }
    
    add_action ('the_title' , 'awards', 10, 2);
    function awards($title, $id) {
      return 'awards' === get_post_type($id) ? '<div>Awards:</div> ' . $title : $title;
    }

    I just added this to functions and POOF! Thank you for your help!

    Alan Fuller

    (@alanfuller)

    That is good you have worked out a solution.

    If that is what you want ( it is different to what you described ) and not really as easy to read as a single function in my opinion.

    As the title is changed every where that title is got in side a loop, single page or archive page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if “custom post type” display this’ is closed to new replies.