Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1121584
    liquidedge
    Participant

    Hi,

    I’ve got a custom post type “Case Studies” set up on my site. I’m looking for a way to customize the _landmark-header.php so that the title is the post type- sounds simple enough!

    See below for my code I have so far which *kinda* works. You’ll see that it pulls in the slug case-study as the title, rather than the far-nicer Case Study
    which is what I want.

                <?php elseif( ! is_singular( array('page', 'attachment', 'post') ) ) : ?>
                
                  <!-- Proper titles for custom post types -->
                  <?php $post_type = get_post_type( $post->ID ); ?>
                  <h1 class="h-landmark"><span>
                    <?php echo $post_type; ?>
                  </span></h1>

    I have also tried using post_type_archive_title(); but it doesn’t seem to output anything. Any help would be appreciated. Login in next post.

    #1121602
    Lely
    Moderator

    Hi There,

    Please try this instead:

    
                <?php elseif(is_singular( array('case-study') ) ) : ?>
                
                  <!-- Proper titles for custom post types -->
                  <?php $post_type = get_post_type( $post->ID ); ?>
                  <h1 class="h-landmark"><span>
                    <?php echo $post_type; ?>
                  </span></h1>

    Change case-study to your custom post type URL.
    If this doesn’t work, please share your single custom post type URL.

    #1122744
    liquidedge
    Participant

    No, that still just renders it as case-study unfortunately.

    Here’s the URL: http://qbuild.nz/case-study/otaki-leaky-home-project/

    Realised I forgot to add the login- it’ll be in the next post.

    Cheers,
    Brad

    #1122745
    liquidedge
    Participant
    This reply has been marked as private.
    #1123280
    Paul R
    Moderator

    Hi Brad,

    Please replace the code with this.

    
          <?php elseif(is_singular( array('case-study') ) ) : ?>
                
                  <!-- Proper titles for custom post types -->
                  <?php $post_type = get_post_type( $post->ID ); ?>
                  <h1 class="h-landmark"><span>
                    <?php echo 'Case Studies' ?>
                  </span></h1>
    

    Thanks

    #1124438
    liquidedge
    Participant

    Hi Paul,

    Yeah- I could do that. But what happens then when I create a new post type? That isn’t at all reusable- hence why I’m trying to do it dynamically in the first place.

    Cheers,
    Brad

    #1124979
    liquidedge
    Participant

    Well, I’ve turned my custom post type Case Studies into a regular category instead, allowing me to use the following code to dynamically get the name of the category for an accurate, relevant page title:

    
    <?php $cats = array();
    foreach (get_the_category($post_id) as $c) {
    $cat = get_category($c);
    array_push($cats, $cat->name);
    }
    
    if (sizeOf($cats) > 0) {
    $post_categories = implode(', ', $cats);
    } else {
    $post_categories = x_get_option( 'x_renew_blog_title' );
    } ?>
    
    <h1 class="h-landmark"><span><?php echo $post_categories; ?></span></h1>
    

    On a side note, do you have a feature request area somewhere? I have numerous pieces of code i’ve built to fix various minor annoyances that other people have. Would be great to be able to suggest some of these as features for future releases.

    #1125013
    Paul R
    Moderator

    Hi,

    Thanks for sharing your code.

    With regards to feature request and sharing of code, you can also post it here in the forum.

    Have a nice day!

  • <script> jQuery(function($){ $("#no-reply-1121584 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>