WordPress.org

Support

Support » Themes and Templates » [Resolved] Get the thumbnails url of my custom post type

[Resolved] Get the thumbnails url of my custom post type

  • WP config
    – Version : 3.4.1
    – PHP/MySQL Version : 5.3
    – Theme : My own
    – Plugins : None
    – Website URL : localhost

    Hello,

    I try to use the thumbnails url of my custom post types “Features” to integrate them into a custom slider, but I encounter an “HIERARCHY_REQUEST_ERR: DOM Exception 3” error.

    <div id=”features_content”>
    <?php $loop = new WP_Query( array( ‘post_type’ => ‘features’, ‘posts_per_page’ => 99 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class=”slider_wrap”>
    <div data-src=”<?php echo get_post_thumbnail_url($post->ID); ?>”>
    <div class=”slider_caption”><?php the_title ?></div>
    <?php the_excerpt(); ?>
    </div>
    <?php endwhile; ?>
    </div>

    functions.php code :

    <?php
    function get_post_thumbnail_url($postid, $imagesize = ‘full’){
    $post_thumbnail_id = get_post_thumbnail_id($postid);
    $image_array = wp_get_attachment_image_src($post_thumbnail_id, $imagesize);
    return $image_array[0];
    }
    ?>

    The url of the thumbnails is ok but nothings displayed.

    How can I get an url that can be used in the data-src of my div ?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • I would use the built in WordPress function rather than your own.

    <?php
    $url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID) );
    echo $url['0'];
    ?>

    Ok, Ive already tried this one but it didnt work.
    Tested again, the problem was the loop call.

    Here the working code :

    <div id=”features_content”>
    <div class=”slider_wrap”>
    <?php $loop = new WP_Query( array( ‘post_type’ => ‘features’, ‘posts_per_page’ => 99 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div data-src=”<?php echo get_post_thumbnail_url($post->ID); ?>”>
    <div class=”slider_caption”><?php the_title ?></div>
    <?php the_excerpt(); ?>
    </div>
    <?php endwhile; ?>
    </div>

    Thanks to redirected me in the right way Steven.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Get the thumbnails url of my custom post type’ is closed to new replies.
Skip to toolbar