본문 바로가기

wordpress/wordpress기초

워드프레스 - 테마 만들기 - 싱글 페이지 만들기

반응형

single.php

the_title() 제목을 출력

the_permalink() URL을 출력

the_author() 필자를 출력

the_content() 내용을 출력

 

the_date() 날짜를 출력 

 

get_the_titlle() 제목을 가져옴

get_the_permalink() URL을 가져옴

get_the_author() 필자를 가져옴

get_the_content() 내용을 가져옴

get_the_date() 날짜를 가져옴

 

 

먼저 글 - 새로추가를 통해 아래와 같은 내용을 작성해준다. 

post와 book(custome post type)은 single.php를 통해 관리가 된다

page는 page.php로 관리가 되며

둘다 는 singular.php로 관리가 된다 

 

single.php

<?php
get_header();

if (have_posts()) {
    while (have_posts()) {
        the_post();
?>
        <article>
            <header>
                <h1><?php the_title(); ?></h1>
            </header>
            <aside>
                <?php the_author(); ?>
                | <?php the_date(); ?>
                | <?php the_permalink(); ?>
            </aside>
            <div>
                <?php the_content(); ?>
            </div>
        </article>
<?php
    }
}

get_footer();

single.php 추가 전 
single.php 추가 후

 

 

위와 비슷한 내용을 page.php에도 적용해본다

 

 

<?php
get_header();

if (have_posts()) {
    while (have_posts()) {
        the_post();
?>
        <article>
            <header>
                <h1><?php the_title(); ?></h1>
            </header>
            <div>
                <?php the_content(); ?>
            </div>
        </article>
<?php
    }
}


get_footer();

 

중복 내용을 singluar.php를 통해 분기처리도 가능하다

singular.php

<?php
get_header();

if (have_posts()) {
    while (have_posts()) {
        the_post();
?>
        <article>
            <header>
                <h1><?php the_title(); ?></h1>
            </header>
            <?php if (!is_page()) {
            ?>
                <aside>
                    <?php the_author(); ?>
                    | <?php the_date(); ?>
                </aside>
            <?php
            } ?>

            <div>
                <?php the_content(); ?>
            </div>
        </article>
<?php
    }
}


get_footer();
반응형