Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter fmarzocca

    (@fmarzocca)

    Sorry, I managed to let it work! My fault.

    Plugin Author philbuchanan

    (@philbuchanan)

    Glad you got it working!

    I know the thread is marked as “resolved”, but since I’m having the same problem I didn’t want to open another one to ask the same exact question.

    A quick note: I’ve put the content in one page for each accordion item – I’ve got three, but I’ll be adding more in the future – and then I’m opening the items via the pages ID. Also, I’m using compatibility mode and I have added the corresponding “as” to every item:

    [as-accordion openfirst="true" openall="false" clicktoclose="true" class="prova-content"]
    [as-accordion-item title="Fierucola, Fierucolona, Rificolona"][my_content id="63"][/as-accordion-item]
    [as-accordion-item title="Fiera della Ceramica"][my_content id="69"][/as-accordion-item]
    [as-accordion-item title="Titoletto 2"]Contenuto 2.[/as-accordion-item]
    [/as-accordion]

    I’ve tried using the code you suggested in another thread, adding the “as” here too:

    <?php
    $content = '[as-accordion]';
    
    $args = array(
        'posts_per_page' => '-1',
        'post_type' => 'post',
        'post_status' => 'publish',
        'category__in' => $quicksand_categories
    );
    $query = new WP_Query( $args );
    foreach ($query->posts as $item) {
        $categories = wp_get_post_categories($item->ID);
        $content .= '[as-accordion-item title="'.get_the_title($item->ID).'"]'.the_content().'[/as-accordion-item]';
    }
    
    $content .= '[/as-accordion]';
    
    echo do_shortcode($content);
    ?>

    But I’m afraid it’s not working as I want him too: I’ve put the code into my sidebar.php and, instead of showing the accordion as it did with the shortcodes, (I’ve been using a text widget until now, but I’m changing the theme quite a bit and I don’t need widgets anymore), it shows the content of the page you’re currently viewing.
    Additionally, it’s ignoring every CSS customization I’ve made so far – see class=”prova-content” in the original shortcode I’ve used in the text widget.

    If you could help me out with this, I’d be most grateful.

    Plugin Author philbuchanan

    (@philbuchanan)

    Just to clarify, the shortcodes are working when put directly into the text widget in WordPress (your first block above), but the second block is not working with do_shortcode()?

    Plugin Author philbuchanan

    (@philbuchanan)

    I think this might be what you are looking for:

    <?php $slides_query = new WP_Query(array(
    	'posts_per_page' => '-1',
    	'post_type'      => 'post',
    	'post_status'    => 'publish'
    ));
    if ($slides_query->have_posts()) :
    	$content = '[as-accordion]';
    		while ($slides_query->have_posts()) : $slides_query->the_post();
    			$content .= '[as-accordion-item title="' . get_the_title() . '"]' . get_the_content() . '[/as-accordion-item]';
    		endwhile;
    	$content .= '[/as-accordion]';
    
    	echo do_shortcode($content);
    endif; wp_reset_postdata(); ?>

    Hi Phil!

    First of all, thanks for your reply.
    To answer your first question: yes, the first block of code works just fine if I put it inside a text widget.

    As for your solution, I’ve found something else that works but I’ve been too busy to post an update on the situation until now.
    Basically, in my sidebar.php, I’ve added this where I want the accordion to appear:

    <?php
    $my_id = 129;
    $post_id_129 = get_post($my_id);
    $content = $post_id_129->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    ?>

    where 129 is the ID of the page I’m taking the content from, (I’ve put the whole accordion – with all the content – into one page insted of having three different pages).

    Now I just have to find a way to get the content with formatting and I’ll be good to go.
    But that’s another story altogether.

    Thank you again and keep up the good work!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Embedding in a page template’ is closed to new replies.