This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Need help adding toggle to a template file

  • Creator
    Topic
  • #15742
    Eleven Sites
    Participant

    Hi Jason,

    I’m trying to have a toggle on a custom post type’s description, as the custom fields that I’ll be showing are more important for the users to browse. I’ve put the following in my template file, but it’s not working. Do I need the [raw] shortcode in the template file? It doesn’t work with or without the [raw] shortcode.

    <?php echo do_shortcode('[raw][toggle title="Description"]'.the_content().'[/toggle][/raw]'); ?>
    and
    <?php echo do_shortcode('[toggle title="Description"]'.the_content().'[/toggle]'); ?>

    Though the toggle appears on the template, it’s empty and the content shows above it.

    Thanks,

    Lindsay

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #15754
    Jason Bobich
    Keymaster

    Hello Lindsay,

    You don’t want to have ‘[raw]’ in there.

    Your specific issue is that you’re using the_content() — This function outputs; it doesn’t return anything. So, in the context where you’re trying to create a string to pass into do_shortcode(), you want to use get_the_content() like this:

    <?php echo do_shortcode('[toggle title="Desc"]'.get_the_content().'[/toggle]'); ?>
    #15758
    Eleven Sites
    Participant

    Yes! Thank you! That fixed it! 🙂

    #16850
    Eleven Sites
    Participant

    Hi Jason,

    Now I’m trying to get custom taxonomies into my toggle. I’m checking to make sure they’re not empty first and then trying to add them into the toggle. The following shows them inside the toggle, but just says “Array” where the taxonomies should be listed.

    I feel like I’m so close… Can you help with the output of these custom taxonomies within the toggle?

    //----Check to see if the custom fields have been assigned a value.  If so, display them with some custom HTML
    //----Using Types render field API
    $manufacturer_fields = "";
    // This one checks for Product Category assignments
    $product_category = get_the_terms( $post->ID, 'product-category', 'Product Categories: ', ', ', ' ' );
    if ( '' != $product_category ) {
    	$manufacturer_fields .= "<i></i> $product_category \n";	
    }
    // This one checks for Product Keyword assignments
    $product_keyword = get_the_terms( $post->ID, 'product-keyword', 'Product Keywords: ', ', ', ' ' );
    if ( '' != $product_keyword ) {
    	$manufacturer_fields .= "<i></i> $product_keyword \n";	
    }
    // This one checks for a photometrics file
    $photometrics_file = types_render_field("photometrics-file", array("id"=>"post-id","output"=>"raw","show_name"=>"false"));
    // Add photometrics file if it exists
    if ( '' != $photometrics_file ) {
    	$manufacturer_fields .= "<i></i><a href="$photometrics_file">Download Photometrics</a>\n";
    }
    // This one checks for a Revit/BIM file
    $revit_bim_file = types_render_field("revit-bim-file", array("id"=>"post-id","output"=>"raw","show_name"=>"false"));
    // Add Revit/BIM file if it exists
    if ( '' != $revit_bim_file ) {
    	$manufacturer_fields .= "<i></i><a href="$$revit_bim_file">Download Revit/BIM File</a>\n";
    }
    // This one checks for a Quick Ship options URL
    $quick_ship = types_render_field("quick-ship", array("id"=>"post-id","output"=>"raw","show_name"=>"false","target"=>"_blank"));
    // Add a Quick Ship options URL if it exists
    if ( '' != $quick_ship ) {
    	$manufacturer_fields .= "<i></i><a href="$quick_ship">View Quick Ship Options</a>\n";
    }
    // Output custom field and taxonomy information if there was any
    // NOTE: We won't even open a div if there's nothing to put inside it.
    
    if ( '' != $manufacturer_fields ) {
    	$info_output = "$manufacturer_fields\n";
    }?>
    #16852
    Jason Bobich
    Keymaster

    I think you’re getting get_the_terms function mixed up with get_the_term_list.

    You’re using get_the_terms(), and passing parameters into meant for get_the_term_list(). And then the root of your problem is that get_the_terms() returns an object of the terms, and the you’re trying to append to $manufacturer_fields, as if it were a string.

    And just FYI; consider this conditional:

    if ( "" != $var ) {
    	// ...
    }

    It is the same as this, which is a more logical way of writing it:

    if ( $var ) {
    	// ...
    }
    #16860
    Eleven Sites
    Participant

    Hi Jason,

    Thanks! Yes, that’s what I needed to get it working correctly.

    Additionally, is there a way to have the content open up above the content? I’m trying to create a v More link that opens the content, and a ^ Less link that shows below the content that closes it. So, I think the content would have to show above the toggle link and the toggle link would have to change if it’s expanded. But, I’m not sure if this is possible.

    Cheers,

    Lindsay

    #16877
    Jason Bobich
    Keymaster

    Unfortunately there’s no way to make the content open above if you’re using the toggle shortcode that’s already setup. You’d have to come up with your own version of the toggle shortcode that had the content above the anchor that opens/closes the content.

    #18901
    Eleven Sites
    Participant

    Hi Jason,

    I just realized that when using the toggle shortcode, the title/link label has an extra space on the front of it. So, if I style my toggle label to have text-decoration: underline; that space shows up. I don’t exactly know where to fix this, so I thought I’d let you know.

    Thanks,

    Lindsay

    #18909
    Jason Bobich
    Keymaster

    In the next update, I will remove the space, and compensate with CSS only for the spacing.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.