Support

Account

Home Forums Add-ons Options Page ACF options page

Solved

ACF options page

  • Hello
    I have the opportunity to test ACF, and i like it a lot.
    I have manage to fix wery much, but it is one thing i don´t understand.

    I add to my function:

    // add sub page
    	acf_add_options_sub_page(array(
    		'page_title' 	=> 'Featured Settings',
    		'menu_title' 	=> 'Featured',
    		'parent_slug' 	=> $parent['menu_slug'],
    	));

    and in my index.php i add <?php get_template_part('inc/features'); ?>

    And in the inc/features i create a page features.php

    <section class="features">
    	<?php if($features = get_field('features', $option)){ ?>
    		<ul class="features__list swiper-wrapper">
    			<?php foreach ($features as $feature) { ?>
    			<li class="features__item swiper-slide">
    				<img class="features__image" src="<?php $feature['image']; ?>" alt="<?php $feature['title']; ?>"
    				draggable="false" />
    				<?php $feature['title']; ?>
    			</li>
    			<?php } ?>
    		</ul>
    	<?php } ?>
    </section>

    in my BO I add a new group features and add one field (title).

    But when I go to the page I don´t see the title, and no errors.
    What have I missed.

  • If your field (text?) is called title, you need to adjust the code:

    
    <?php
    $title = get_field('title', option);
    if( $title );
      echo $title;
    endif;
    ?>

    The code you’ve shown above is a repeater field. It’s also option not $option

  • Ok, i havent come to repeater yet, how does that works.

  • Check the docs

    But basically:

    <?php
    
    // Check rows exists.
    if( have_rows('repeater_field_name',option') ):
    
        // Loop through rows.
        while( have_rows('repeater_field_name','option') ) : the_row();
    
            // Load sub field value.
            $sub_value = get_sub_field('sub_field');
            // Do something...
    
        // End loop.
        endwhile;
    
    // No value.
    else :
        // Do something...
    endif;
  • AAAA Im going nuts.

    All i can see is :

    <section class="features">
    <ul class="features__list swiper-wrapper">
    <li class="features__item swiper-slide">
    <img class="features__image" src="" alt="" draggable="false">
    </li>
    </ul>
    </section>

    My field group is Feature, and repeater Features
    Do I missing something.

    <section class="features">
    <?php 
        if( have_rows('features', option) ): ?>
        <ul class="features__list swiper-wrapper">
        <?php while( have_rows('features','option') ): the_row(); ?>
            <li class="features__item swiper-slide">
                <img class="features__image" src="<?php $feature['image']; ?>" alt="<?php $feature['title']; ?>"
    				draggable="false" />
                <?php $feature('title'); ?>
            </li>
        <?php endwhile; ?>
        </ul>
    <?php endif; ?>
    </section>
  • manage to fix it myself:

    <section class="features">
    <?php 
        if( have_rows('features', option) ): ?>
        <ul class="features__list swiper-wrapper">
        <?php while( have_rows('features','option') ): the_row();
        $image = get_sub_field('image'); 
        $title = get_sub_field('title');
        ?>
            <li class="features__item swiper-slide">
                <img class="features__image" src="<?php echo $image['url']; ?>" alt="<?php echo $title; ?>"
    				draggable="false" />
                <?php echo $title; ?>
            </li>
        <?php endwhile; ?>
        </ul>
    <?php endif; ?>
    </section>
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.