Tagged: x
-
AuthorPosts
-
August 7, 2016 at 11:31 pm #1121584
liquidedgeParticipantHi,
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.
August 8, 2016 at 12:01 am #1121602
LelyModeratorHi 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.August 8, 2016 at 4:08 pm #1122744
liquidedgeParticipantNo, 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,
BradAugust 8, 2016 at 4:08 pm #1122745
liquidedgeParticipantThis reply has been marked as private.August 9, 2016 at 1:35 am #1123280
Paul RModeratorHi 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
August 9, 2016 at 4:13 pm #1124438
liquidedgeParticipantHi 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,
BradAugust 9, 2016 at 11:34 pm #1124979
liquidedgeParticipantWell, 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.
August 10, 2016 at 12:11 am #1125013
Paul RModeratorHi,
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!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1121584 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
