WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Featured Image
[resolved] Integration Troubles (11 posts)

  1. theoriginaljordan
    Member
    Posted 8 months ago #

    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,

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

  2. Ankit Pokhrel
    Member
    Plugin Author

    Posted 8 months ago #

    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: http://ankitpokhrel.com.np/blog/

  3. theoriginaljordan
    Member
    Posted 8 months ago #

    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,

  4. Ankit Pokhrel
    Member
    Plugin Author

    Posted 8 months ago #

    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?

  5. theoriginaljordan
    Member
    Posted 8 months ago #

    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

  6. Ankit Pokhrel
    Member
    Plugin Author

    Posted 8 months ago #

    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 } ?>
  7. theoriginaljordan
    Member
    Posted 8 months ago #

    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

  8. Ankit Pokhrel
    Member
    Plugin Author

    Posted 8 months ago #

    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

  9. theoriginaljordan
    Member
    Posted 8 months ago #

    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,

  10. Ankit Pokhrel
    Member
    Plugin Author

    Posted 8 months ago #

    Hi,

    If its possible please attach and send me your theme folder to ankitpokhrel@gmail.com. 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

  11. theoriginaljordan
    Member
    Posted 8 months ago #

    Thanks, just emailed you!

Reply

You must log in to post.

About this Plugin

About this Topic