• This is an invaluable plugin! I am using it for a page which allows up to 10 featured images, and it’s all working a treat.

    However it would be great to have a ‘for’ or a ‘foreach’ loop to register a large amount of featured images, as the code to register 10 new featured images becomes very long when repeated ten times. I have tried myself but can’t get it to work. I imagine it would have to be something similar to the following:

    <?php if(class_exists('kdMultipleFeaturedImages')) {
    	for ($i = 1; $i <= 10; $i++) {
    		$args{$i} = array(
    			'id' => 'featured-image-{$i+1}',
    			'post_type' => 'page',      // Set this to post or page
    			'labels' => array(
    				'name'      => 'Featured image {$i+1}',
    				'set'       => 'Set featured image {$i+1}',
    				'remove'    => 'Remove featured image {$i+1}',
    				'use'       => 'Use as featured image {$i+1}',
    			)
    		);
    		new kdMultipleFeaturedImages( $args{$i} );
    	}
    } ?>

    If anyone knows how to do this it would be really useful!

    http://wordpress.org/extend/plugins/multiple-featured-images/

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    if(class_exists('kdMultipleFeaturedImages')) {
    	for ($i = 2; $i <= 10; $i++) {
    		$args[$i] = array(
    			"id" => "featured-image-$i",
    			"post_type" => "page",      // Set this to post or page
    			"labels" => array(
    				"name"      => "Featured image $i",
    				"set"       => "Set featured image $i",
    				"remove"    => "Remove featured image $i",
    				"use"       => "Use as featured image $i",
    			)
    		);
    	new kdMultipleFeaturedImages($args[$i]);
    	}
    }
    ?>

    this works for me 🙂

    Thread Starter indirectdesign

    (@indirectdesign)

    Thank you very kindly! I knew I was close… I am just about to begin work on phase 2 of the website in question so it will be great to have the option of streamlining that code. I look forward to reporting back with positive results. Many thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using a for loop to register 10 featured images’ is closed to new replies.