WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Featured Image
[resolved] Show 2nd Featured Image in Slider (8 posts)

  1. CMYKreative
    Member
    Posted 3 months ago #

    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/

  2. Ankit Pokhrel
    Member
    Plugin Author

    Posted 3 months ago #

    Hello CMYKreative,

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

    Thanks,
    Ankit

  3. CMYKreative
    Member
    Posted 3 months ago #

    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?

  4. CMYKreative
    Member
    Posted 3 months ago #

    Ankit?

  5. Ankit Pokhrel
    Member
    Plugin Author

    Posted 3 months ago #

    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(); ?>
  6. CMYKreative
    Member
    Posted 3 months ago #

    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? :)

  7. Ankit Pokhrel
    Member
    Plugin Author

    Posted 3 months ago #

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

  8. CMYKreative
    Member
    Posted 3 months ago #

    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! :)

Reply

You must log in to post.

About this Plugin

About this Topic