Skip to content

Instantly share code, notes, and snippets.

@qholzweg
Last active October 6, 2018 11:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qholzweg/8052500 to your computer and use it in GitHub Desktop.
Save qholzweg/8052500 to your computer and use it in GitHub Desktop.
Wordpress get_posts with thumb
<?php
$args = array('post_type' => array('page'), 'order' => 'ASC', 'orderby' => 'date'/*
to sort by custom fields
, 'meta_query' => array(
array(
'key' => 'meta',
'value' => true,
)
)
*/
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
?>
<div class="page">
<?php
if ( has_post_thumbnail()) :
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'mediunm');
$small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail');
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?= $full_image_url[0] ?>" /></a>
<?php endif; ?>
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
<?php endforeach; ?>
@wiesys
Copy link

wiesys commented Oct 6, 2018

Thanks! wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); was I was looking for!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment