Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author shazdeh

    (@shazdeh)

    Hi,

    That is possible, although a bit of custom coding would be required. The has_term function requires two parameters and the shortcode works with only one, so you could first add this to the functions.php file of your theme:

    function custom_has_chapter( $term ) {
       return has_term( $term, 'chapter' );
    }
    function custom_has_media( $term ) {
       return has_term( $term, 'media' );
    }

    Now in the shortcode you could use custom_has_chapter parameter:

    [if custom_has_chapter="one"] This text is only displayed if current post has chapter "one" [/if]

    Or combine those:

    [if custom_has_chapter="one"] [if custom_has_media="sound"] This text is only displayed if current post has chapter "one" and "sound" media taxonomies [/if] [/if]
    Thread Starter mhairilongmuir

    (@mhairilongmuir)

    Thank you very much for that, much appreciated.

    So, I’m using that, and it seems to be working (I think). The only thing is that the 2nd closing if tag is also showing? Eg. ‘[/if]’ is showing on my page, do you know why this is happening?

    Cheers

    Thread Starter mhairilongmuir

    (@mhairilongmuir)

    Hi,

    On looking at it properly, it doesn’t seem to be working. Maybe I should explain better and you can tell me if the code above will fit what I’m trying to do…

    The two custom taxonomies that I have are called:

    • interaction-media-types
    • chapter

    And the taxonomy terms are:

    • interaction-media-types: activities-tools, audio, images, useful-web-links, videos
    • chapter: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

    Here is the [edited] code that you have provided me with, that I’m using:

    function custom_has_chapter( $term ) {
       return has_term( $term, 'chapter' );
    }
    function custom_has_media( $term ) {
       return has_term( $term, 'interaction-media-types' );
    }

    My site is set up as a companion site for an ebook, and each page is associated with one of the 13 chapters. There is content at the bottom of the page for each chapter, which is split into a media type, showing in accordions. What I’m trying to do, is only make that accordion show if there is content associated with that chapter, and media type, ie. chapter: 1, media type: video has content in it, but it’s not currently showing anything (aside from a [/if] tag?) when using the following code:

    [if custom_has_chapter="1"][if custom_has_media="video"]
    [toggle title_open="Video" title_closed="Video" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="videos" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[thumbnail]">[field image="thumbnail" size="thumbnail"]</a>
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    [/if][/if]

    Do you know where I’m going wrong? Many thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Does it work with custom taxonomies?’ is closed to new replies.