Last active
February 25, 2017 07:12
-
-
Save s-hiroshi/3088098 to your computer and use it in GitHub Desktop.
Wordpress - スニペット - foreach文を使用した基本ループのサンプルです。
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
/** | |
* foreachを使ったサンプル | |
* | |
* reffer | |
* get_posts | |
* http://codex.wordpress.org/Template_Tags/get_posts | |
*/ | |
<?php | |
$args = array( | |
'posts_per_page' => 5, | |
'offset' => 0, | |
'category' => '', | |
'category_name' => '', // category_name is category slug | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'include' => '', | |
'exclude' => '', | |
'meta_key' => '', | |
'meta_value' => '', | |
'post_type' => 'post', | |
'post_mime_type' => '', | |
'post_parent' => '', | |
'author' => '', | |
'post_status' => 'publish', | |
'suppress_filters' => true | |
); | |
$lastposts = get_posts($args); | |
?> | |
<?php foreach($lastposts as $post) : setup_postdata($post); ?> | |
<p><?php the_time("Y/m/d"); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> | |
<?php endforeach; ?> | |
<?php wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment