카테고리 24번 글을 15개 가져오려면
$catquery = new WP_Query( 'cat=24&posts_per_page=15' );
예시
<?php
$catquery = new WP_Query( 'cat=24&posts_per_page=15' ); // 카테고리 ID, 글개수
while($catquery->have_posts()) : $catquery->the_post();
?>
<a href="<?php the_permalink() ?>">
<div class="img">
<?php if( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( 'custom-th' ); ?>
<?php else : ?>
<img class="not-found" src="./image-not-found.png" alt="">
<?php endif; ?>
</div>
<div>
<p class="title"><?php the_title(); ?></p>
<p class="subtext"><?php custom_length_excerpt(20); ?></p>
</div>
</a>
<?php endwhile; ?>
썸네일 이미지와 글자수도 조절하려면
function.php 에 아래 코드를 추가한다.
/ 블로그 셋업
function my_theme_setup(){
// 포스트 썸네일 등록하기
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-th', 320, 220, true );
}
add_action( 'after_setup_theme', 'my_theme_setup' );
// 요약 글자수
function custom_length_excerpt($word_count_limit) {
$content = wp_strip_all_tags(get_the_content() , true );
echo wp_trim_words($content, $word_count_limit);
}
글자수 말줄임표 CSS
.list ul li {
display: block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 200px;
}
'WP' 카테고리의 다른 글
사용자 정의 필드 추가 및 적용 (플러그인 없이) (0) | 2024.04.30 |
---|---|
워드프레스 특정페이지, 특정 카테고리 템플릿 (0) | 2024.04.30 |
워드프레스 메뉴 등록 코드 (0) | 2024.04.30 |
워드프레스 테마 경로 주소 (0) | 2024.04.30 |
워드프레스 관리자 로그인 화면 디자인 수정 (0) | 2024.04.30 |
워드프레스 페이지별로 헤더이미지 class 바꾸기 (0) | 2024.04.30 |
워드프레스 새글쓰기 버튼 (0) | 2024.04.30 |
워드프레스 첨부파일 경로 한번에 다 바꾸기 (0) | 2024.04.30 |