programing

WP -- 카테고리별로 투고를 취득하시겠습니까?

kakaobank 2023. 3. 18. 08:47
반응형

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

반응형