Skip to content

Instantly share code, notes, and snippets.

@mirzap
Forked from paulgosnell/Get thumbnail src
Created September 20, 2012 18:22
Show Gist options
  • Save mirzap/3757517 to your computer and use it in GitHub Desktop.
Save mirzap/3757517 to your computer and use it in GitHub Desktop.
commonly used snippets of WP code
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div class="bgImg" style="background:url(<?php echo $image[0]; ?>) no-repeat 50% 50%;"></div>
<?php endif; ?>
<?php
$args = array(
'numberposts' => 10,
'order'=> 'ASC',
'orderby' => 'title'
);
$postslist = get_posts( $args ); foreach ( $postslist as $post ) : setup_postdata($post); ?>
<?php the_date(); ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
Display a list of 5 posts selected randomly by using the MySQL RAND() function for the orderby parameter value:
<?php
$args = array(
'numberposts' => 5,
'orderby' => 'rand'
);
$rand_posts = get_posts( $args ); foreach ( $rand_posts as $post ) : ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment