<?php
$args = array(
'category_name' => 'recom',
'posts_per_page' => get_theme_mod( 'mainslidimg_num', 8 ), // 갯수는 사용자정의
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query($args);
if ($query->have_posts()) {
echo '<ul class="swiper-wrapper">';
while ($query->have_posts()) {
$query->the_post();
?>
<li class="scrollTop col swiper-slide" data-animate="movetop">
<a href="<?php echo get_permalink(); ?>">
<div class="imgbox">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail('post-thumbnail-img');
} else {
$content = apply_filters('the_content', get_the_content());
preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
$first_image_url = isset($matches[1]) ? $matches[1] : '';
if ($first_image_url) {
echo '<img src="' . esc_url($first_image_url) . '" alt="' . get_the_title() . '" />';
} else {
echo '<img src="' . esc_url(get_template_directory_uri() . '/img/default-thumbnail.jpg') . '" alt="Default Thumbnail" />';
}
}
?>
</div>
<div class="textbox">
<p class="title"><?php the_title(); ?></p>
<p class="excerpt">
<?php
if (has_excerpt()) {
the_excerpt();
} else {
$content = wp_trim_words(get_the_content(), 30, '...');
echo $content;
}
?>
</p>
</div>
</a>
</li>
<?php
}
echo '</ul>';
wp_reset_postdata();
} else {
echo '글이 없습니다.';
}
?>
'WP' 카테고리의 다른 글
워드프레스 사이트에 어떤 플러그인 썼는지 알려주는 사이트 (0) | 2024.09.12 |
---|---|
워드프레스에 카카오지도 반응형으로 넣기 (0) | 2024.09.07 |
케이보드 최근게시물 디자인 수정하기 (0) | 2024.09.04 |
워드프레스 페이지별로 다른 헤더 파일 가져오기 (0) | 2024.08.30 |
워드프레스 파비콘(Favicon) 추가 코드 (0) | 2024.08.30 |
까페24 호스팅에 워드프레스 설치 후 해야 하는 것 (0) | 2024.08.30 |
wp 테마, 플러그인 제작 참고 (0) | 2024.08.08 |
all in one 복제시 용량 에러날때 .htaccess (0) | 2024.05.01 |