[resolved] do_shortcode on closing isn't working (3 posts)

  1. Marj Wyatt
    Posted 3 years ago #

    I am wondering what I'm doing wrong.

    I've found a plugin that will apply accordion styles to content using shortcodes. Here is the link for that plugin:

    For my custom theme project, there are several categories that my client wants to expand to display all the posts in those categories so I would like to use this plugin to accomplish that.

    Since my client will be adding new content after my work is complete, I've been trying to work out how to use the do_shortcode function in a custom page template to expand the categories to clickable links.

    Here is a link to the code that I've written as a test:

    The code is "almost working" except for the fact that the closing shortcode is displaying as content at the end of the list which is causing the accordion to fail.

    Can anyone help me understand what I'm doing wrong?

  2. Michael
    Part-Time Forum Moderator
    Posted 3 years ago #

    you possibly need to parse the full shortcode;

    example (untested - make a backup of your existing files before trying):

    <?php $shrt_cd = "[accordion title='Menus & Parties']";
        query_posts( array ( 'category_name' => 'menus-parties' ) );
            $shrt_cd .= '<ul>';
            while (have_posts()) : the_post();
                    $shrt_cd .= '<li><a href="'.get_permalink().'">';
                    $shrt_cd .= get_the_title();
                    $shrt_cd .= '</a></li>';
            $shrt_cd .= '</ul>';
            $shrt_cd .= "[/accordion]";
            echo do_shortcode( $shrt_cd ); ?>
  3. Marj Wyatt
    Posted 3 years ago #

    Hey Alchymyth ...

    That worked great! Thanks so much.

Topic Closed

This topic has been closed to new replies.

About this Topic