워드프레스(WordPress)의 Template Tags – 한국워드프레스사용자모임 https://kopress.kr/topic/%ec%9b%8c%eb%93%9c%ed%94%84%eb%a0%88%ec%8a%a4wordpress%ec%9d%98-template-tags/feed/ Wed, 01 May 2024 17:25:13 +0000 https://bbpress.org/?v=2.6.9 ko-KR https://kopress.kr/topic/%ec%9b%8c%eb%93%9c%ed%94%84%eb%a0%88%ec%8a%a4wordpress%ec%9d%98-template-tags/#post-500 <![CDATA[워드프레스(WordPress)의 Template Tags]]> https://kopress.kr/topic/%ec%9b%8c%eb%93%9c%ed%94%84%eb%a0%88%ec%8a%a4wordpress%ec%9d%98-template-tags/#post-500 Mon, 02 May 2005 09:43:00 +0000 그림동화 워드프레스(WordPress)의 개발자인 Matt가 자신의 블로그에
“워드프레스(WordPress)는 PHP 가 아니다.”
(http://mattread.com/archives/2005/04/wordpress-is-not-php/)

라는 제목으로 워드프레스에서 사용되는 탬플렛 시스템에 대한 포스팅을 했습니다.

Matt는 탬플렛을 바꾸기 위해 PHP 를 알 필요가 없다고 이야기 하면서
워드프레스이 탬플렛을 설명하면서 앞으로 개선되어야 할 부분도 제시하였습니다.

다음은 Matt가 설명한 워드프레스 탬플렛 시스템의 개념을 기본으로 내용을 정리한 것입니다.

(워드프레스의 테마 파일 시스템에 대한 내용은 다음에 다시 정리하겠습니다.)

0. 들어가기 전에

탬플렛 태그를 이용하면 보여지는 화면의 출력을 바꿀 수 있습니다.

1. the Loop

워드프레스 탬플렛에는 the Loop(http://codex.wordpress.org/The_Loop)라는 개념이 있습니다.
이것은 작성된 포스트를 보여줄때 사용됩니다. the Loop 태그안에 내용에 따라 포스트를
실제로 어떻게 보여줄지 결정되는 것입니다.

the Loop 태그의 시작은 다음과 같습니다.

(1) the Loop 태그 시작 부분

———————————————————————-

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

———————————————————————

the Loop 태그의 끝은 다음과 같습니다.

(2) the Loop 태그 끝 부분
————————————————————–
<?php endwhile; else: ?>
<p><?php _e(‘미안해용~ 포스트가 없어서~’); ?></p>
<?php endif; ?>
—————————————————————

즉 (1) the Loop 태그 시작 부분 과 (2) the Loop 태그 끝 부분 에 에 무엇이
오는가에 따라 포스트의 내용이 어떻게 출력되는지 결정되는 것입니다.
참고로 (2) the Loop 태그 끝 부분에 “미안해용~ 포스트가 없어서~” 부분은 포스트가
없을때 보여지는 메세지라는 것을 알수 있습니다. 포스트가 없다면
“미안해용~ 포스트가 없어서~” 라고 나옵니다.

즉 the Loop 문의 전체적인 구조는 다음과 같습니다.

—————————————————————-

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

탬플렛 부분 1: 포스트가 보여질때 태그를 여기에 구현합니다.

<?php endwhile; else: ?>

템플렛 부분 2 : 포스트가 없을 때 태그는 여기에 구현합니다.

<?php endif; ?>

——————————————————

이제 (1) 과 (2) 사이에 들어가는 템플렛 부분 1을 만들어 보겠습니다.

—————————–
템플렛 1 부분

<div class=”post”>
<h2> <?php the_title() ?> </h2>
<p> <?php the_date() ?> </p>

<?php the_content() ?>
</div>

————————

여기서

<?php the_title() ?>
<?php the_date() ?>
<?php the_content() ?>

부분이 바로 워드프레스 태그입니다.

<p></p> 부분은 HTML 태그입니다. ^^

각 워드프레스 태그의 기능은 다음과 같습니다.

<?php the_title() ?> 는 제목을 출력합니다.
<?php the_date() ?> 는 날짜를 출력합니다.
<?php the_content() ?>는 본문을 출력합니다.

여기까지 보면

the Loop 문의 시스템이 어떻게 구성되는지 알수 있을 것입니다.

한번 출력되는 부분에 퍼머링크를 추가하겠습니다.

—————————————————————-
<div class=”post”>
<h2> <a href=”<?php the_permalink() ?>”> <?php the_title() ?> </a> </h2>
<p> <?php the_date() ?> </p>

<?php the_content() ?>

<?php link_pages(‘<p>’,'</p>’) ?>
</div>
—————————————————————
<a href=”<?php the_permalink() ?> 가 추가되었습니다.

여기에서 <a href=””> 는 HTML 태그 입니다.

다음은 실제로 워드프레스 default 테마의 (1)과 (2) 사이에 나오는 내용입니다.

the Loop 시작부분
———————————————————————————-
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
——————————————————————–

탬플렛 부분 1
————————————————————-
<div class=”post”>
<h2 id=”post-<?php the_ID(); ?>”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a></h2>
<small><?php the_time(‘Y년 F j일’) ?> <!– by <?php the_author() ?> –></small>

<div class=”entry”>
<?php the_content(‘모두 읽기 &raquo;’); ?>
</div>

<p class=”postmetadata”><?php the_category(‘, ‘) ?> <strong>|</strong> <?php edit_post_link(‘수정’,”,'<strong>|</strong>’); ?> <?php comments_popup_link(‘답글 없음 »’, ‘1개의 답글 »’, ‘%개의 답글 »’); ?></p>

<!–
<?php trackback_rdf(); ?>
–>
</div>

—————————————————————————–
the Loop 끝부분 (1)
——————————————————————-
<?php endwhile; ?> ->

<div class=”navigation”>
<div class=”alignleft”><?php posts_nav_link(”,”,’&laquo; 이전 글’) ?></div>
<div class=”alignright”><?php posts_nav_link(”,’다음 글 &raquo;’,”) ?></div>
</div>

<?php else : ?>
————————————————————————
탬플렛 부분 2
———————————————————————-

<h2 class=”center”>Not Found</h2>
<p class=”center”><?php _e(“미안합니다. 조건에 맞는 글이 없습니다.”); ?></p>
<?php include (TEMPLATEPATH . “/searchform.php”); ?>

———————————————————————-

the Loop 끝부분 (2)
———————————————–
<?php endif; ?>

——————————————————————————-

내용은 몰라도 전체적인 구조를 아시겠지요

여기서 the Loop 끝부분 (1) 중 중간에 나오는
———————————————————————-

<div class=”navigation”>
<div class=”alignleft”><?php posts_nav_link(”,”,’&laquo; 이전 글’) ?></div>
<div class=”alignright”><?php posts_nav_link(”,’다음 글 &raquo;’,”) ?></div>
</div>

—————————————————————————

는 이전글과 다음글의 링크가 나오는 부분이라는 것은 알수 있습니다.

이제 탬플렛 1 부분을 살펴보겠습니다. 결론부터 말하면 탬플렛 1 부분은
탬플렛 태그로 이루어져 있습니다. 테터에서 치환자를 다루어 보신 분이라면 이해 하실것입니다.

탬플렛 1에 나오는 태그를 살펴보겠습니다.

——————————————————
<?php the_ID(); ?>
<?php the_permalink() ?>
<?php the_title(); ?>
<?php the_time(‘Y년 F j일’) ?>
<?php the_author() ?>
<?php the_content(‘모두 읽기 &raquo;’); ?>
<?php the_category(‘, ‘) ?>
<?php edit_post_link(‘수정’,”,'<strong>|</strong>’); ?>
<?php comments_popup_link(‘답글 없음 »’, ‘1개의 답글 »’, ‘%개의 답글 »’); ?></p>
<?php trackback_rdf(); ?>

——————————————————————————-

태그는 해당 포스트의 ID, 퍼머링크(고유주소), 제목, 시간, 저자, 카테고리 , 본문내용, 글수정
덧글 팝업창등을 나타내고 있습니다. 이 태그를 어떻게 구성하고 사용하는가에 따라 원하는 화면을 구성 할수 있는 것입니다.
(태그가 각각 어떤 의미인지는 여기서는 생략하겠습니다.)

the Loop 사이에서 사용되는 태그 리스트를 보여드리겠습니다.
(워드프레스 태그에 관심있으신 분은 http://codex.wordpress.org)를 참고 하시면 됩니다.)

(1) 글쓴이관련 태그

the_author
the_author_description
the_author_login
the_author_firstname
the_author_lastname
the_author_nickname
the_author_ID
the_author_email
the_author_url
the_author_icq
the_author_aim
the_author_yim
the_author_msn
the_author_posts
the_author_posts_link
list_authors
wp_list_authors

(2) 카테고리 관련 태그

the_category
the_category_rss
the_category_ID (Deprecated)
the_category_head (Deprecated)
single_cat_title
category_description
dropdown_cats
list_cats
wp_list_cats
in_category
get_category_parents

(3) 덧글 관련 태그

comments_number
comments_link
comments_rss_link
comments_popup_script
comments_popup_link
comment_ID
comment_author
comment_author_IP
comment_author_email
comment_author_url
comment_author_email_link
comment_author_url_link
comment_author_link
comment_type
comment_text
comment_excerpt
comment_date
comment_time
comment_author_rss
comment_text_rss
comment_link_rss
permalink_comments_rss

(4) 날짜와 시간 태그

the_date_xml
the_date
the_time
get_the_time (1.5 only)
single_month_title
the_weekday (Deprecated)
the_weekday_date (Deprecated)

(5) Geo 태그

print_Lat
print_Lon
print_UrlPopNav
print_AcmeMap_Url
print_GeoURL_Url
print_GeoCache_Url
print_MapQuest_Url
print_SideBit_Url
print_DegreeConfluence_Url
print_TopoZone_Url
print_FindU_Url
print_MapTech_Url

(6) 일반 태그

bloginfo
bloginfo_rss
wp_title
get_archives
wp_get_archives
get_calendar
get_posts
wp_list_pages (1.5 only)
wp_loginout (1.5 only)
wp_register (1.5 only)
query_posts (1.5 only – coming soon)

(7) 링크 태그

edit_post_link
edit_comment_link
link_pages
wp_link_pages
get_year_link
get_month_link
get_day_link

(8) 링크관리태그

get_links_list
wp_get_links
get_links
wp_get_linksbyname
get_linksbyname

(9) 퍼머링크 태그

permalink_anchor
get_permalink
the_permalink
permalink_single_rss

(10) 포스트 태그

the_ID
the_title
single_post_title
the_title_rss
the_content
the_content_rss
the_excerpt
the_excerpt_rss
previous_post
next_post
posts_nav_link
the_meta

————————————

여기까지입니다. ^^;

]]>