반응형
WP -- 카테고리별로 투고를 취득하시겠습니까?
페이지 템플릿에서 이 항목을 사용하여 카테고리별로 게시물을 가져옵니다.
<?php
if (is_page(19)){
?>
<ul>
<?php
global $post;
$args = array( 'category' => 'Testimonial' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
</ul>
<?php } ?>
대신 모든 게시물을 가져옵니다.'증거'라는 이름만요내가 뭘 잘못하고 있는지 알기나 해?
'category_name'=> 'this cat'도 작동하지만 WP 문서에는 인쇄되지 않습니다.
https://developer.wordpress.org/reference/functions/get_posts/ 를 참조해 주세요.
주의: 카테고리 파라미터는 카테고리명이 아닌 카테고리의 ID여야 합니다.
파라미터에는 'category_name'을 사용할 수 있습니다.http://codex.wordpress.org/Template_Tags/get_posts
주의: category_name 파라미터는 문자열이어야 합니다.이 경우 카테고리 이름입니다.
add_shortcode( 'seriesposts', 'series_posts' );
function series_posts( $atts )
{ ob_start();
$myseriesoption = get_option( '_myseries', null );
$type = $myseriesoption;
$args=array( 'post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => 5, 'caller_get_posts'=> 1);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<ul>';
while ($my_query->have_posts()) : $my_query->the_post();
echo '<li><a href="';
echo the_permalink();
echo '">';
echo the_title();
echo '</a></li>';
endwhile;
echo '</ul>';
}
wp_reset_query();
return ob_get_clean(); }
//사이트에서 사용하는 쇼트 코드 함수가 생성됩니다.[시리즈 포스트]
분류법 필드 범주(필드 이름 = post_category)를 생성하여 아래와 같이 템플릿으로 가져옵니다.
<?php
$categ = get_field('post_category');
$args = array( 'posts_per_page' => 6,
'category_name' => $categ->slug );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
//your code here
<?php endforeach;
wp_reset_postdata();?>
언급URL : https://stackoverflow.com/questions/11909304/wp-get-posts-by-category
반응형
'programing' 카테고리의 다른 글
| 워드프레스:서버에서 로컬 호스트로 다중 사이트 이동 (0) | 2023.03.18 |
|---|---|
| ng각 2에서 작동하지 않는 텍스트 영역 모델 (0) | 2023.03.18 |
| json 어레이 스트림을 한 번에 하나씩 역직렬화 (0) | 2023.03.18 |
| 워드프레스에서 mysql 쿼리를 실행하려면 어떻게 해야 하나요? (0) | 2023.03.18 |
| 샘플 스프링 부트애플리케이션의 필드에 로거를 주입하려면 어떻게 해야 합니까? (0) | 2023.03.18 |