- This topic has 9 replies, 3 voices, and was last updated 6 years, 11 months ago by Tom.
-
AuthorPosts
-
May 9, 2017 at 11:52 am #315967dasigna
hi there again,
little question about tweaking the appearance of cpts… if you dont mind.
having taxonomys for custom post type and wanting to show them right after the post title… works fine so far with the following code applied via after page title hook:<div class="work-single"><?php echo get_the_term_list( $post->ID, 'work', '<h3>Work</h3><span class="tax-link">', ' ' ); ?></span></div>
so i am able to style the output how i want it to be and everything is showing up fine…
BUT:
the issue is: this applies to all pages not only to the relevant ones of the ‘work’ cpts.
so my (first) question would be if there is a comfortable way to expand the snipplet so this hook only would target pages that refer to the certain type (cpt ‘work’)? simply because the code is there also on every page, and even if theres noting to show up, applied paddings etc affects the other pages.and second question would be if theres any snipplet, that generally prevents the featured image to be shown on (single) pages of that custom post type. would be easier not having to think about that every time one of those cpts is generated and manually tick that ‘disable elements’ box.
thanks in advance for any hint or help.
May 9, 2017 at 12:06 pm #315971LeoStaffCustomer SupportHi there,
I think you can use conditional tags for that:
https://codex.wordpress.org/Conditional_Tags#A_Single_Page.2C_a_Single_Post.2C_an_Attachment_or_Any_Other_Custom_Post_TypeLots of good information on that page.
As for hiding the featured image, try something like this:
https://generatepress.com/forums/topic/hiding-featured-images-from-single-post-display-in-custom-post-type/#post-298153Let me know.
May 9, 2017 at 8:07 pm #316088TomLead DeveloperLead DeveloperI think the conditional you’re looking for is: is_tax()
May 10, 2017 at 12:50 am #316195dasignathanks to leo and tom.
yes, already found the conditional, and got it to work… partly.
the problem for me until now is, that the php part of the hook is hidden on other pages than ‘work’, but not the divs outside the php. which results in still interfering content through div/css.maybe everything in the hook should be wrapped in <?php…?> but didnt managed to get to that point without getting errors all the time… π
right thought or not?as for hiding the featured image for all cpt single pages: the css-thing only seems to work if a dedicated template for the cpts is used… which is not the case so far.
best thing to do so – or is there another way?May 10, 2017 at 7:39 am #316328TomLead DeveloperLead DeveloperYea, the conditional should be around the entire block of code. If you’re running into errors, you can share your complete code in here and I’ll take a look.
Can you link me to a page where that CSS isn’t working?
May 10, 2017 at 11:46 am #316464dasignahi tom,
second thing first:
the css for hiding feat. image IS working. it was my fault applying it to the wrong class so it did not show anywhere (but should only not on single cpt pages). now all seems fine. thanks.wrapping the hook in php:
i tend towards making it the easier way πthis is the final content for the generate_after_entry_title hook with the classes to style the output:
<div class="arbeit-single-entry"><?php echo get_the_term_list( $post->ID, 'arbeitsbereich', '<b>Arbeitsbereich  </b><span class="ab-cat-link">', ' ' ); ?></span></div> <div class="arbeit-kunde"><b>Kunde  </b><span class="kunde-single"><?php echo get_post_meta(get_the_ID(), 'wpcf-kunde', TRUE); ?></span></div>
this works, but injects into every page (naturally).
as the post type (!) is ‘arbeiten’ i tried to wrap it into this condition
if ( is_singular( 'arbeiten' ) ) { //put code here// }
that seems to work in principle, but either way i am wrapping the hook content there are errors.
wont bother you with the tryouts because my php knowledge is close to zero and might cause shocks on your side as i assume…
in short: it seems to work for the php part when wrapping (and i get this done) but when trying to implement the divs and wrap them also (which is the need obviously) i run into issues. simply because i am not able to sort out all those nasty little characters that make the difference.so if you could have a look into this i would be very happy π
May 10, 2017 at 12:02 pm #316476dasignahmmm …
tried this a second ago once again and now it seems to work as expected:
<?php if ( is_singular( 'arbeiten' ) ) { ?><div class="arbeit-single-entry"><?php echo get_the_term_list( $post->ID, 'arbeitsbereich', '<b>Arbeitsbereich  </b><span class="ab-cat-link">', ' ' ); ?></span></div> <div class="arbeit-kunde"><b>Kunde  </b><span class="kunde-single"><?php echo get_post_meta(get_the_ID(), 'wpcf-kunde', TRUE); ?></span></div><?php } ?>
really weird! tried for dont know how often and did not… something seems kidding me.
done the right way now???May 10, 2017 at 7:30 pm #316543TomLead DeveloperLead DeveloperAny HTML inside PHP needs to be closing off:
?>HTML in here<?php
Glad you got it working π
May 11, 2017 at 2:05 am #316642dasignaAny HTML inside PHP needs to be closing off:
yeah, noticed that. but funny enough same code didnt work at first… so started tweaking and messed things up – obviously. hard life sometimes being more designer than coder… ratio 100:1 i think π
but anyway, works now.
thanks for lending a hand even if worked it out myself in the end. great theme (kind of swiss knife for wordpress) and great support. love it more and more.
pin post already at the border of my screens – some coffees announced when next paid project is finished.
May 11, 2017 at 9:16 am #316775TomLead DeveloperLead DeveloperThank you! π
-
AuthorPosts
- You must be logged in to reply to this topic.