• I am trying to create a theme for a company and one of the requirements is that there testimonial page must always be two click away from their site. In other words the user must read and accept a disclaimer before they can view the sites testimonials. No matter how they come across the page.
    I created a custom blog called testimonials and from there they will be able to add their clients testimonies. Is their a way to create a category-testimonial template that will hide the content of the blogs until after the users agrees to the disclaimer?
    The site can be found here
    http://www.silverliningherbs.com
    If you go to the site and click on products testimonials then you will see what I am trying to accomplish on the new theme I am building for them.
    How this was accomplish on the old theme is through shortcode. The theme developer made a shortcode to display all of the testimonials post. He then used another shortcode to hide the testimonial shortcode until after the disclaimer was agreed to. the editor of the page looks like this:
    [hidden_content]

    [testimonials]

    [/hidden_content]

    I tried this by copying his code but for some reason I cannot get the hidden shortcode to hide the testimonials shortcode.
    Beside I would like to do this through a template if at all possible.
    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You’ll have to look at the old theme and see how they’ve done the

    [hidden_content]

    shortcode. That will let you see how it was done, and you should be able to copy that sortcode across to your new theme.

    Thread Starter silvermatthew

    (@silvermatthew)

    I did just that. the problem that I am running into is that the [hidden_content] short code will hide text if you go like this
    [hidden_content_disclaimer button_text=”I agree to the disclaimer”] some random texts goes here…
    [/hidden_content_disclaimer]
    But when I place the short code [testimonials] in between the hidden_content like this
    [hidden_content]

    [testimonials]

    [/hidden_content]
    The testimonials shortcode still executes. All though the users have not click the agreement link. The disclaimer is there but so are all the testimonies. I will past the code for the the hidden content as well as the disclaimer if you think it will help.

    /*———————————————————————————–*/

    /* Show hidden content after user accepts disclaimer */

    /*———————————————————————————–*/

    function slh_hidden_content_disclaimer($atts, $content) {

    extract(shortcode_atts(array(

    ‘href’ => ‘#’,

    ‘button_text’ => ‘I agree to the disclaimer’

    ), $atts));

    $output = “<div id=’content-disclaimer-button’>”.do_shortcode($content);

    $output .= “<p>“.$button_text.”</p></div>”;

    return $output;

    }

    add_shortcode(‘hidden_content_disclaimer’,’slh_hidden_content_disclaimer’);

    /*———————————————————————————–*/

    /* Hide content until user accepts disclaimer */

    /*———————————————————————————–*/

    function slh_hidden_content($atts, $content) {

    extract(shortcode_atts(array(

    ‘div_class’ => ‘content-unapproved’,

    ‘button_text’ => ‘I agree to the disclaimer’

    ), $atts));

    ?>

    <style type=”text/css”>

    .content-unapproved {

    display: none;

    }

    </style>

    <script type=”text/javascript”>

    var double_click = false;

    jQuery(document).ready(function($) {

    //console.log(‘ready to go!’);

    $(“#approve-disclaimer”).on(‘click’, function(e){

    e.preventDefault;

    e.stopImmediatePropagation;

    e.stopPropagation;

    $(‘link[rel=”icon”]’).attr(‘href’,’http://smattmyers.com/missing-logo.png&#8217;);

    $(‘link[rel=”shortcut icon”]’).attr(‘href’,’http://smattmyers.com/missing-logo.png&#8217;);

    var nav = $(“#nav”);

    var new_nav = $(“#new-nav”);

    var c = $(“.content-unapproved”);

    c.show(‘fast’);

    $(“#content-disclaimer-button”).hide(‘fast’);

    $(“#content”).css({

    ‘background’: “white”,

    ‘width’: “100%”,

    ‘height’: “auto”,

    ‘position’: “absolute”,

    ‘z-index’: 999,

    ‘border’: “15px solid gray”,

    ‘padding’: 20,

    ‘top’: -290,

    ‘left’:-20

    });

    var url = (getCookie(‘lastLocation’) ? getCookie(‘lastLocation’): ‘http://www.silverliningherbs.com&#8217;);

    var return_button = “Return to Silver Lining Herbs “;

    new_nav.append(return_button);

    new_nav.css({‘margin-top’:’44px’});

    setTimeout(function(){double_click = true;},1000);

    $(“#theBody”).css({‘background-image’:’none’});

    $(“.bg-shadow.group”).css({‘background’:’none’,’background-image’:’none’});

    });

    $(document).on(‘click’, ‘a’, function(e) {

    if (double_click) {

    alert(‘You are now returning to the Silver Lining Herbs website’);

    }

    });

    });

    </script>

    <?php

    $output = “<div id=’hidden-content’ class=’content-unapproved’><div id=’new-nav’></div>”;

    $output .= do_shortcode($content);

    $output .= “</div>”;

    return $output;

    }

    add_shortcode(‘hidden_content’,’slh_hidden_content’);

    If someone could help me figure out why it is not hidden the shortcode [testimonial] then I will go that route.
    Thanks for your help.

    Thread Starter silvermatthew

    (@silvermatthew)

    Now that I look more closely, it also has to do also with the way he set up his shortcode for [testimonial].
    I will look more into this and if I figure this out I will mark this as solved. However if someone knows of a way to set up a template that can achieve the desire results I would still like to know.
    Thanks you for your help.

    Moderator bcworkz

    (@bcworkz)

    The nested shortcodes are problematic. Nothing that can’t be resolved, but this scheme doesn’t look to be very secure to me. It appears one could simply disable their CSS or view the page source to see the “hidden” content. Maybe this is not that critical and that risk is acceptable, but I’d advocate a more secure scheme where script has to get the hidden data from the server as a separate request. And it would only work if the proper “key” is included with the request.

    The initial part the user sees before accepting terms can still be managed by shortcode, but the hidden part ought to be in its own private post where only script or the author are able to retrieve the data. I suppose the hidden part could still be managed by shortcode if it was that important a feature, but it’s rather messy to do so, especially when nested shortcodes are involved.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘how to create a show/hide template’ is closed to new replies.