-
-
Save mirzap/3757517 to your computer and use it in GitHub Desktop.
commonly used snippets of WP code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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