워드프레스 php ‘wp_get_archives’ 를 활용해 포스트 아카이브를 맘대로 표현할 수 있다.
사용법(Usage)
<?php wp_get_archives( $args ); ?>
기본 사용법(Default Usage)
<?php $args = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'post_type' => 'post' ); wp_get_archives( $args ); ?>
파라미터(Parameters)
type
(string) The type of archive list to display. Defaults to WordPress settings. Valid values:
limit
(integer) Number of archives to get. Default is no limit.
format
(string) Format for the archive list. Valid values:
before
(string) Text to place before the link when using the html or custom for format option. There is no default.
after
(string) Text to place after the link when using the html or custom for format option. There is no default.
show_post_count
(boolean) Display number of posts in an archive or do not. For use with all type except 'postbypost'.
echo
(boolean) Display the output or return it.
order
(string) How to order the link list (since Version 3.5)
post_type
(”string”) Limit archives to a post type. Default is 'post'. (since Version 4.4)
예제(Examples)
<?php $my_archives=wp_get_archives(array( 'type'=>'alpha', 'show_post_count'=>true, 'limit'=>20, 'post_type'=>'post', 'format'=>'html' )); print_r($my_archives); ?>
지난 12개월(Last Twelve Months)
<?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 12 ) ); ?>
지난 20개 포스트(Last Twenty Posts)
<?php wp_get_archives( array( 'type' => 'postbypost', 'limit' => 20, 'format' => 'custom' ) ); ?>
드롭다운 박스(Dropdown Box)
<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option> <?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?> </select>
간단 활용(Easy use)
//전체 포스트 <?php wp_get_archives('type=postbypost'); ?> //최근 포스트 10개 <?php wp_get_archives('type=postbypost&limit=10'); ?>
참조 원문 https://codex.wordpress.org/Function_Reference/wp_get_archives