0

I'm trying to use a jquery toggle shortcode in a theme template.

The shortcode goes like this:

[sws_toggle3 title="Title"]You can now see the displayed text.[/sws_toggle3] 

I want to pull posts from a specific category and use the toggle to display them in the page.

This is what my theme template currently has:

 <?php $wp_query->query('cat=11&paged=' . $paged); while ($wp_query->have_posts()) : $wp_query->the_post();?> <li id="post-<?php the_ID(); ?>"> <h2><a class="title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="post"> <?php the_content(); ?> </div> <div class="clear"></div> </li> <?php endwhile; ?> 

With the output being something like:

[sws_toggle3 title="<?php the_title(); ?>"]<?php the_content(); ?>[/sws_toggle3] 

Is this possible? Any help would be much appreciated.

Thanks

    2 Answers 2

    1

    You should be able to use do_shortcode(), with a few modifications:

    <?php echo do_shortcode( '[sws_toggle3 title="' . get_the_title() . '"]' . get_the_content() . '[/sws_toggle3]' ); ?> 

    EDIT

    If you need to maintain the formatting of the_content(), simply pass get_the_content() through the appropriate filter:

    <?php $content = get_the_content(); $content = apply_filters( 'the_content', $content ); echo do_shortcode( '[sws_toggle3 title="' . get_the_title() . '"]' . $content . '[/sws_toggle3]' ); ?> 
    5
    • ah, beat me to it!
      – Milo
      CommentedJul 18, 2011 at 2:09
    • More like, we both posted at exactly the same time!CommentedJul 18, 2011 at 2:23
    • This worked, but lost the formatting as well.
      – shinyidol
      CommentedJul 18, 2011 at 2:48
    • See update for how to maintain formatting.CommentedJul 18, 2011 at 11:04
    • I tried the update and still doesn't hold the formatting. Tried modifying, but still no dice. <?php $wp_query->query('cat=11&paged=' . $paged); while ($wp_query->have_posts()) : $wp_query->the_post(); $content = get_the_content(); $content = apply_filters( 'the_content', $content ); echo do_shortcode( '[sws_toggle3 title="' . get_the_title() . '"]' . $content . '[/sws_toggle3]' );?> <?php endwhile; ?> this is what i have right now
      – shinyidol
      CommentedJul 24, 2011 at 3:06
    1

    use do_shortcode():

    $wp_query->query('cat=11&paged=' . $paged); while ($wp_query->have_posts()) : $wp_query->the_post(); $content = apply_filters( 'the_content',get_the_content() ); $title = the_title('','',false); $shortcode = '[sws_toggle3 title="'.$title.'"]'.$content.'[/sws_toggle3]'; echo do_shortcode($shortcode); endwhile; 
    1
    • Thanks! I both of them worked to get the toggle to pull the content, the title and content lost all its formatting.
      – shinyidol
      CommentedJul 18, 2011 at 2:47

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.