• Resolved Jordan

    (@theoriginaljordan)


    Hello,

    I am currently trying to set up Dynamic Featured Images with my theme.
    I am having trouble doing so. I just keep breaking the loop. I am trying to replace this get_children call with dfi call.

    <?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' =>
    'attachment', 'post_mime_type' => 'image') );
    if ( $attachments ) { ?>

    and

    $attachments = get_children(array('post_parent' => $post->ID,
     'post_status' => 'inherit',
     'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'order' => 'ASC',
    'orderby' => 'menu_order ID'));
    foreach($attachments as $att_id => $attachment) {
    $medium_img_urls = wp_get_attachment_image_src( $attachment->ID, 'featured_list_image' );
    ?>

    Any help would be much appreciated!

    Thanks,

    https://www.ads-software.com/plugins/dynamic-featured-image/

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

    (@ankitpokhrel)

    Hi,

    Thank your using the plugin. I guess you are already inside a loop so you can just call the function like this:

    $attachments= dfi_get_featured_images( $post->ID );

    and to get the medium image url you can use following function:

    $medium_img_urls = dfi_get_image_url( $attachments['attachment_id'], 'medium' );

    You can learn more about these functions at https://github.com/ankitpokhrel/Dynamic-Featured-Image/wiki/Available-Functions

    You may also find this blog useful: https://ankitpokhrel.com.np/blog/

    Thread Starter Jordan

    (@theoriginaljordan)

    Ankit,

    Thanks so much for the support. I can’t tell you how much you are helping!
    I am still receiving an error “Undefined index: attatchment_id”. I apologize for my ignorance.

    Here is the whole block of code I am working with.

    <div class="post-image-box entry-image">
    
    <?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    
    if ( $attachments ) { ?>
    
    <?php
    
    /* add javascript */
    wp_enqueue_script( 'agurghis-flexslider' );
    
    ?>
    
    <?php if ($current==0) { ?>
    
    <script type='text/javascript'>
    jQuery(function() {
    jQuery('#post-<?php the_ID(); ?> .flexslider').flexslider( {
    slideshowSpeed: 4200,
    animationSpeed: 500,
    });
    });
    </script>
    
    <?php } elseif ($current==1) { ?>
    
    <script type='text/javascript'>
    jQuery(function() {
    jQuery('#post-<?php the_ID(); ?> .flexslider').flexslider( {
    slideshowSpeed: 2900,
    animationSpeed: 200,
    });
    });
    </script>
    
    <?php } elseif ($current==2) { ?>
    
    <script type='text/javascript'>
    jQuery(function() {
    jQuery('post-<?php the_ID(); ?> .flexslider').flexslider( {
    slideshowSpeed: 5600,
    animationSpeed: 200,
    });
    });
    </script>
    
    <?php } elseif ($current==3) { ?>
    
    <script type='text/javascript'>
    jQuery(function() {
    jQuery('#post-<?php the_ID(); ?> .flexslider').flexslider( {
    slideshowSpeed: 4800,
    animationSpeed: 300,
    });
    });
    </script>
    
    <?php } elseif ($current==4) { ?>
    
    <script type='text/javascript'>
    jQuery(function() {
    jQuery('#post-<?php the_ID(); ?> .flexslider').flexslider( {
    slideshowSpeed: 3400,
    animationSpeed: 150,
    });
    });
    </script>
    
    <?php } ?>
    
    <div class="flexslider">
    
    <ul class="slides">
    
    <?php
    
    $attachments = get_children(array('post_parent' => $post->ID,
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'order' => 'ASC',
    'orderby' => 'menu_order ID'));
    
    foreach($attachments as $att_id => $attachment) {
    
    $medium_img_urls = wp_get_attachment_image_src( $attachment->ID, 'featured_list_image' );
    
    ?>
    
    <li>
    
    <a class="gall-img" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <img src="<?php echo $medium_img_urls[0]; ?>" alt="<?php echo $attachment->post_title; ?>" />
    
    </a>
    
    </li>
    
    <?php
    }
    ?>
    
    </ul>
    
    </div>
    
    <?php } else { ?>
    
    <a class="gall-img entry-image" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <?php the_post_thumbnail('featured_list_image'); ?>
    
    </a>
    
    <?php } ?>
    
    </div>

    Thanks again,

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Looks like the error message is because of a typo. It’s attachment_id not “attatchment_id”. Can you fix the typo and let me know if it fixed it or not?

    Thread Starter Jordan

    (@theoriginaljordan)

    The typo was not the issue I do not believe.

    Here is the code as it is now.

    <?php
    
    $attachments = dfi_get_featured_images($post->ID);
    
    foreach($attachments as $att_id => $attachment) {
    
    $medium_img_urls = dfi_get_image_url( $attachments['attachment_id'], 'featured_list_image' );
    
    ?>
    
    <li>
    
    <a class="gall-img" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <img src="<?php echo $medium_img_urls[0]; ?>" alt="<?php echo $attachment->post_title; ?>" />
    
    </a>
    
    </li>
    
    <?php
    }
    ?>
    
    </ul>
    
    </div>
    
    <?php } else { ?>
    
    <a class="gall-img entry-image" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <?php the_post_thumbnail('featured_list_image'); ?>
    
    </a>
    
    <?php } ?>

    This still gives me the undefined index: attachment_id

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    I guess you are little confused with the proper implementation of the plugin. Try following code:

    <?php
    
    $attachments = dfi_get_featured_images($post->ID);
    
    foreach($attachments as $attachment) {
    
    $medium_img_url = dfi_get_image_url( $attachment['attachment_id'], 'medium' );
    
    ?>
    
    <li>
    
    <a class="gall-img" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <img src="<?php echo $medium_img_url; ?>" alt="<?php echo dfi_get_image_alt_by_id($attachment['attachment_id']); ?>" />
    
    </a>
    
    </li>
    
    <?php
    }
    ?>
    
    </ul>
    
    </div>
    
    <?php } else { ?>
    
    <a class="gall-img entry-image" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    
    <?php the_post_thumbnail('featured_list_image'); ?>
    
    </a>
    
    <?php } ?>
    Thread Starter Jordan

    (@theoriginaljordan)

    Thanks again for the help/patience.
    I am new to the PHP world.

    The code is no longer giving me an error but this is what is printed for the img tag
    ‘<img src=”” alt=””>’

    Here is the page if you want to see for yourself.
    whirlmagazine.com/test

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hi,

    The problem is completely related to your coding issues. The plugin is working as it should. The alt field is empty because you need to set the alt field of the image in media library. Regarding empty source, try attaching the featured image by removing previous one. This usually happens if you delete the image you attached previously. Its attachment id will no longer exist or may be the medium thumbnail was not created for that image.

    The link you provided is broken. You need to use debugging techniques to find the issue.

    Thanks,
    Ankit

    Thread Starter Jordan

    (@theoriginaljordan)

    Thanks for the advice. I am still having trouble. I did try re-setting the featured images to no avail. I have set alt attributes and still nothing is getting pulled for the img src or alt. If you can no longer help me that’s fine but it would be very appreciated.

    Thanks,

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hi,

    If its possible please attach and send me your theme folder to [email protected]. Also let me know the WordPress version you are using. I would love to help you but i cannot do anything without checking the issue manually.

    Thanks,
    Ankit

    Thread Starter Jordan

    (@theoriginaljordan)

    Thanks, just emailed you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Integration Troubles’ is closed to new replies.