• Resolved TatsujinUK

    (@tatsujinuk)


    We have the plugin installed but are having trouble finding the correct code to show the “2nd” featured image within our page.

    What we had originally (before adding the plugin) was the (below code), where we use <?php echo $theImage[0] ?> (in the li as a background image) . . . what do we replace here to pull in the “2nd” featured image we’ve addded to the post?

    Here’s the code of the page:

    <?php query_posts(array(
    	'post_type' 	=> 'cs_action',
    	'meta_key'    => 'action_no',
      'orderby'     => 'meta_value_num',
      'order'       => 'ASC',
      'posts_per_page' => -1
    	# 'post__in'  => get_option('sticky_posts'),
    ));
    $item_index = 0;
    ?>
    
    <ul class="slider">
      <?php
    	while(have_posts()): the_post();
    	$action_no = (int)get_post_meta($post->ID, 'action_no', true);
    	?>
      <?php if (has_post_thumbnail()):
    	$dom = simplexml_load_string(get_the_post_thumbnail());
    	$theImage = $dom->attributes()->src;
    	?>
      <li style="background-image: url(<?php echo $theImage[0] ?>);" data-href="<?php the_permalink() ?>">
        <div class="panel">
          <div class="copy"> <span>
            <?php _e('TAKE ACTION') ?>
            </span>
            <h2>
              <?php the_title() ?>
            </h2>
          </div>
        </div>
        <div class="copyright"><?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?></div>
      </li>
      <?php endif ?>
      <?php endwhile ?>
    </ul>
    <?php wp_reset_query(); ?>

    https://wordpress.org/plugins/dynamic-featured-image/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hello CMYKreative,

    Please go through this thread. If you are still confused feel free to contact.

    Thanks,
    Ankit

    Thread Starter TatsujinUK

    (@tatsujinuk)

    Thanks Ankit, I’ve been through ALL the threads and tried many different things but cannot get it to work.

    Are you able to tell me what we need to add or change in our above code to enable us to target that 2nd featured image?

    Thread Starter TatsujinUK

    (@tatsujinuk)

    Ankit?

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Sorry! Forgot to reply your thread.

    Try something like this:

    <?php query_posts(array(
    	'post_type' 	=> 'cs_action',
    	'meta_key'    => 'action_no',
      'orderby'     => 'meta_value_num',
      'order'       => 'ASC',
      'posts_per_page' => -1
    	# 'post__in'  => get_option('sticky_posts'),
    ));
    $item_index = 0;
    ?>
    
    <ul class="slider">
      <?php
      global $dynamic_featured_image;
    	while(have_posts()): the_post();
    	$action_no = (int)get_post_meta($post->ID, 'action_no', true);
      $second_image = $dynamic_featured_image->get_nth_featured_image( 2, get_the_ID() ); //gives you the second featured image of current post or null if it doesn't exist
    	?>
      <?php if (has_post_thumbnail()):
    	$dom = simplexml_load_string(get_the_post_thumbnail());
    	$theImage = $dom->attributes()->src;
    	?>
      <li style="background-image: url(<?php echo $second_image ?>);" data-href="<?php the_permalink() ?>">
        <div class="panel">
          <div class="copy"> <span>
            <?php _e('TAKE ACTION') ?>
            </span>
            <h2>
              <?php the_title() ?>
            </h2>
          </div>
        </div>
        <div class="copyright"><?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?></div>
      </li>
      <?php endif ?>
      <?php endwhile ?>
    </ul>
    <?php wp_reset_query(); ?>

    Thread Starter TatsujinUK

    (@tatsujinuk)

    Thanks, but that didn’t work either.

    When we load the page, the url’s for the images are:

    http://www.domainname.com/Array

    Any ideas? 🙂

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Sorry my mistake. Try changing <?php echo $second_image ?> to <?php echo $second_image['thumb'] ?> or <?php echo $second_image['full'] ?>

    Thread Starter TatsujinUK

    (@tatsujinuk)

    Thank you Ankit, that [‘full’] version worked perfectly and now allows us to have different header images for the home and specific action page . . . here’s where we are using it:

    http://childsafetourism.org/

    Thanks for the help! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show 2nd Featured Image in Slider’ is closed to new replies.