코딩

Archive 하는 방법

코딩저니 렉스 2022. 12. 16. 15:18

워드프레스에서 Archive는 archive.php 파일을 사용한다.

<?php
get_header(); ?>

<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo get_theme_file_uri('/images/ocean.jpg') ?>)"></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title"><?php if (is_category()) {
single_cat_title();
}
if (is_author()) {
echo 'Posts by ';the_author();
}?> </h1>
<div class="page-banner__intro">
<p>Keep up with our latest news.</p>
</div>
</div>
</div>

<div class="container container--narrow page-section">
<?php
while(have_posts()) {
the_post(); ?>
<div class="post-item">
<h2 class="headline headline--medium headline--post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="metabox">
<p>Posted by <?php the_author_posts_link(); ?> on <?php the_time('n.j.y'); ?> in <?php echo get_the_category_list(', '); ?></p>
</div>
<div class="generic-content">
<?php the_excerpt(); ?>
<p><a class="btn btn--blue" href="<?php the_permalink(); ?>">Continue reading &raquo;</a></p>
</div>
<?php
}
echo paginate_links();
?>
</div>

<?php get_footer();


?>


최근에 출시된 archive 기능(function) 사용하기.

the_archive_title 기능을 사용하면 카테고리/작가/날짜 별로 페이지 제목을 변경할 수 있습니다. 

그리고 the_archive_description을 사용하면 해당 카테고리/작가/날짜에 대한 워드프레스 관리자에서 설정한 설명을 표시하도록 할 수 있습니다.

 
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo get_theme_file_uri('/images/ocean.jpg') ?>)"></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title"><?php the_archive_title(); ?></h1>
<div class="page-banner__intro">
<p><?php the_archive_description(); ?></p>
</div>
</div>
</div>

더 상세한 코딩을 하고 싶으면 위에 archive 기능을 아니면 간단히 the_archive_title 기능을 사용하도록 권장한다.