• Resolved lexxlevi

    (@lexxlevi)


    Hello, thank you for your great work.
    I try to put advanced custom fields in accordeon codes, but it seems, the div´s are closing in a wrong way, as you can see here

    <?php if( get_field('akkordeon') ): ?>
    		<?php echo do_shortcode('[accordion clicktoclose="true"]'); ?>
    		<?php if( have_rows('reihen') ): ?>
    		<?php while(has_sub_field('reihen')): ?>
    		<?php 
    		$akkordeontitelvar = get_sub_field('akkordeontitel');		
    		echo do_shortcode('[accordion-item title="' . $akkordeontitelvar . '"] ')?>
    		<div class="columns">
    			<!-- .content-->
    		</div>
    		<!-- .columns -->
    		<?php echo do_shortcode('[/accordion-item] ')?>
    		<?php endwhile; ?>
    		<?php endif; ?>
    		<?php echo do_shortcode('[/accordion] ')?>
    <?php endif; ?>

    What I am doing wrong, can you help me, please?
    Thank you in advance
    ll.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author philbuchanan

    (@philbuchanan)

    You have to group the entire block into a single do_shortcode() function call. Something like this:

    <?php echo do_shortcode('[accordion clicktoclose="true"][accordion-item title="' . $akkordeontitelvar . '"]Content here[/accordion-item][/accordion]'); ?>

    Thread Starter lexxlevi

    (@lexxlevi)

    ooops, that is going very complicated for me, because the content has some php code in it.

    <?php if( get_field('akkordeon') ): ?>
    		<?php echo do_shortcode('[accordion clicktoclose="true"]'); ?>
    		<?php if( have_rows('reihen') ): ?>
    		<?php while(has_sub_field('reihen')): ?>
    		<?php 
    		$akkordeontitelvar = get_sub_field('akkordeontitel');		
    		echo do_shortcode('[accordion-item title="' . $akkordeontitelvar . '"] ')?>
    		<div class="columns">
    			<div class="left-col-text">
    				<?php the_sub_field('textinhalt'); ?>
    			</div>
    			<div class="right-col-image">
    				<!-- Bildleiste Standard-->
    				<?php if( have_rows('beitragsbilder-reihe') ): ?>
    				<?php while(has_sub_field('beitragsbilder-reihe')): ?>
    				<div class="bild">
    					<div class="bild-standard" style="background-image:url(<?php the_sub_field('beitragsbild-2'); ?>);">
    
    						<?php if( get_sub_field('link_zu_datei') ): ?>
    
    						<a href="<?php the_sub_field('datei_link'); ?>" target="_blank"></a>
    
    						<?php else : ?>
    
    						<a href="<?php the_sub_field('beitragsbild-2'); ?>" rel="lightbox[uniqueID|filename]" data-slb-active="1" data-slb-internal="0"></a>
    						<?php endif; ?>
    					</div>
    					<!-- .bild-standard -->
    					<div class="bildunterschrift">
    						<?php if( get_sub_field('bildunterschrift-2') ): ?>
    						<?php the_sub_field('bildunterschrift-2'); ?>
    						<?php endif; ?>
    					</div>
    					<!-- .bildunterschrift -->
    				</div>
    				<!-- .bild -->
    				<?php endwhile; ?>
    				<?php endif; ?>
    			</div>
    			<!-- .right-col-image -->
    		</div>
    		<!-- .columns -->
    		<?php echo do_shortcode('[/accordion-item] ')?>
    		<?php endwhile; ?>
    		<?php endif; ?>
    		<?php echo do_shortcode('[/accordion] ')?>
    		<?php else : ?>

    I will give my best but hopefully it is not impertinent to ask you for some tipps, how to implement all this html and php into an echo function…? You see, I’m not very good at these things, but if you have an idea, I’ll try to work out the rest 🙂

    Plugin Author philbuchanan

    (@philbuchanan)

    I would suggest building the entire HTML string a variable first, then passing that variable into the do_shortcode() function. As an example:

    <?php $content = '[accordion]';
    $akkordeontitelvar = get_sub_field('akkordeontitel');
    $content .= '[accordion-item title="' . $akkordeontitelvar . '"]';
    $content .= '<div class="columns"><div class="left-col-text">';
    $content .= get_sub_field('textinhalt');
    $content .= '</div></div>';
    $content .= '[/accordion-item]';
    $content .= '[/accordion]';
    
    echo do_shortcode($content); ?>

    You will have to figure out the rest of the content side, but you should be able to following that structure.

    • This reply was modified 6 years, 11 months ago by philbuchanan.
    Thread Starter lexxlevi

    (@lexxlevi)

    thank you very much, you helped me really a lot 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Accordeon and ACFields’ is closed to new replies.