WordPress.org

Ready to get started?Download WordPress

Forums

archive.php hack (2 posts)

  1. phatpatpjp1
    Member
    Posted 1 year ago #

    I am trying to insert the archive.php code into a php enabled widget. I removed the header, sidebar, footer calls. The code works great, it shows everything correctly but the image. On the archive page it works fine, but in the widget, it shows the same image(thumbnail, featured image) for every post..

    archive code attached

    http://pastebin.com/4DWc0Pjh

    it has an if/else for how to display image, it displays the image from line 72 when used in the widget, I am guessing it has having trouble getting the link for the featured image or image from the post to use for the thumbnail.

    Why would it work when used in the archive.php, and not in the widget, everything works in the widget but the featured image. Could it need a function from another script?

    Thanks for any help -Pat

  2. Umbercode
    Member
    Posted 1 year ago #

    As far as I know, bdw_get_images is not part of WordPress core? So without knowing what that function does it is difficult to say why it doesn't work.
    You can get attached pictures using only wp core functions in a number of ways, for example:

    $args = array(
    	'post_type'      => 'attachment',
    	'post_parent'    => $post->ID,
    	'post_mime_type' => 'image'
    );
    $images = get_posts($args);
    echo '<img src="'.wp_get_attachment_url($images[0]->ID, 'thumbnail', false, false).'" />';

    I didn't test this code, so tread carefully.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.