Black Friday Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] custom post type tweaking with hook

Home Forums Support custom post type tweaking with hook

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #315967
    dasigna

    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">', '&ensp;' ); ?></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.

    #315971
    Leo
    Staff
    Customer Support
    #316088
    Tom
    Lead Developer
    Lead Developer
    #316195
    dasigna

    thanks 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?

    #316328
    Tom
    Lead Developer
    Lead Developer

    Yea, 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?

    #316464
    dasigna

    hi 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 &ensp;</b><span class="ab-cat-link">', '&ensp;' ); ?></span></div>
    <div class="arbeit-kunde"><b>Kunde &ensp;</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 🙂

    #316476
    dasigna

    hmmm …

    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 &ensp;</b><span class="ab-cat-link">', '&ensp;' ); ?></span></div>
    <div class="arbeit-kunde"><b>Kunde &ensp;</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???

    #316543
    Tom
    Lead Developer
    Lead Developer

    Any HTML inside PHP needs to be closing off: ?>HTML in here<?php

    Glad you got it working 🙂

    #316642
    dasigna

    Any 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.

    #316775
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.