본문 바로가기

Wordpress/워드프레스 노하우

워드프레스 wp_query 관련해서

워드프레스 post를 carousel 형태로 커스터마이징 하려다 기획이 수정되었다.

여기다 갈무리해둬야징


<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(

'post_type'        => 'post',

'orderby'          => 'date',

'order'            => 'DESC',

'posts_per_page'   => 3,

'category_name' => 'latest-news',

    'post_status'      => 'publish',

'paged'            => $paged

);

$the_query = new WP_Query($args);

if ( $the_query->have_posts() ) :

    while ( $the_query->have_posts() ) : $the_query->the_post();


        $imgThumb = wp_get_attachment_image( get_post_thumbnail_id( $the_query->ID ), "", "", array( "class" => "img-responsive" ) );

//없으면     $imgThumb = ( !empty($imgThumb) ) ? $imgThumb[0] : get_bloginfo('template_url') . '/assets/img/img-default-blog-thumbnail.gif';


?>

<div class="index_blog_wrap">

<figure><?php echo $imgThumb; ?></figure>

<div class="index_blog_desc">

<a href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>">

<div class="index_blog_desc_text">

<span class="quote"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/quote.png" alt="quote"></span>

<?php the_excerpt(); ?>

</div>

</a>

</div>

</div>

<?php

    endwhile;

?>


<?php

    wp_reset_postdata();

endif;

?>