WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Marj Wyatt
    Member
    Posted 1 year 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:
    http://patrick.forringer.com/2011/04/wordpress-content-accordion/

    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:
    http://pastebin.com/BuWkrPus

    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. alchymyth
    Forum Moderator
    Posted 1 year 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>';
            endwhile;
            $shrt_cd .= '</ul>';
            $shrt_cd .= "[/accordion]";
            echo do_shortcode( $shrt_cd ); ?>
  3. Marj Wyatt
    Member
    Posted 1 year ago #

    Hey Alchymyth ...

    That worked great! Thanks so much.

Topic Closed

This topic has been closed to new replies.

About this Topic