• I use the below php statement to generate 6 item at my customize but my main challenge now is how to echo this at my loop section. The one have below is just repeating only one item. What should i do to display each of the listed item at the customizer?

    					<?php
    	 for ( $count = 1; $count <= 5; $count++ ) {?>
    					<article class="col-lg-4 col-md-6 col-sm-6 mb-3">
    						<div class="card border-0">
    							<i class="fa fa-refresh fa-spin fa-2x"></i>
    							<h6><?php echo esc_html( $ize_theme_hero_title  ); ?> </h6>
    							<p class="text-muted">
    								Complete installation and configuration guide to enable you to use our WordPress theme to its fullest.
    							</p>
    						</div>
    					</article>
    <?php }
    ?>
    
    for ( $count = 1; $count <= 6; $count++ ) {
    	$wp_customize->add_setting('ize_theme_why_choose_us_item_icon-' . $count, array(
    		'default'    => 'fa fa-user',
    		'sanitize_callback' => 'sanitize_text_field',
    	));
    	
    	$wp_customize->add_control('ize_theme_why_choose_us_item_icon-' . $count, array(
    		'label' => __('Font Awesome icon', 'ize-theme' ),
    		'description' => __( 'Select font awesome icons <a target="_blank" href="https://astronautweb.co/snippet/font-awesome/" rel="noopener">Click Here</a> for select icon', 'ize-theme' ),
    		'section' => 'ize_theme_why_choose_us_section',
    		'type'=> 'text',
    		'input_attrs' => array( // Optional.
            'placeholder' => __( 'Enter Fontawesome icon ...', 'ize-theme' ),
      		),
    	) );
    }
    • This topic was modified 3 years, 7 months ago by bcworkz.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You need source data for anything you want to be different for each iteration of the loop that can be referenced by $count. An indexed array works well for this.

    $source = array('one','two','three',);
    for ( $count = 0; $count <= 2; $count++ ) {
       echo "Code is in iteration {$source[$count]}<br>\n";
    }

    Note that arrays are indexed base 0, not 1.
    You can create a multi-dimensional array to contain more elaborate data structures. You could instead use conditional structures within the loop like switch/case or if/elseif/else, but personally I prefer the source data array for most situations.

    Thread Starter shaibustephen

    (@shaibustephen)

    Noted. from what i have about in the costumizer setting and control is ize_theme_why_choose_us_item_icon-, how do interrelate it to have different items in array such as $source = array(‘one’,’two’,’three’,);?
    Do i need to add number to it such as ize_theme_why_choose_us_item_icon-1, ize_theme_why_choose_us_item_icon-2, ize_theme_why_choose_us_item_icon-3 to form same thing as $source = array(‘ize_theme_why_choose_us_item_icon-1′,’ize_theme_why_choose_us_item_icon-2′,’ize_theme_why_choose_us_item_icon-3’,);

    Moderator bcworkz

    (@bcworkz)

    Because PHP is loosely typed, you can concatenate an integer to a string. You can simply do this:
    'section' => "ize_theme_why_choose_us_section-$source",
    or
    'section' => 'ize_theme_why_choose_us_section-'. $source,
    You can use variables within double quoted strings, but not single quoted.

    In my earlier example I had thought what needed to be iterated into the data was more complex than a simple integer. Such an array technique would still work, but it’s overly complex for simple numeric iteration.

    Thread Starter shaibustephen

    (@shaibustephen)

    I am grateful. Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘forcount+++ in customizer’ is closed to new replies.