WordPress 튜토리얼: HTML에서 WordPress 테마를 만드는 방법(1부)
- 1. 현재 읽고 있는 내용: WordPress 튜토리얼: HTML에서 WordPress 테마를 만드는 방법(1부)
- <스팬>2. WordPress 튜토리얼: HTML에서 WordPress 테마를 만드는 방법(2부)
- <스팬>3. WordPress 테마의 구조 소개
HTML(+CSS) 웹사이트로 시작했다면 워드프레스로 이동할 때 모든 것을 버릴 필요는 없습니다. HTML을 WordPress로 변환하고 동적 WordPress 플랫폼에서 (이제 더욱 강력한) 웹사이트를 실행할 수 있습니다.
아니면 그렇지 않을 수도 있습니다. 아마도 클라이언트의 HTML 디자인을 완전한 WordPress 테마로 변환하는 방법이 궁금할 것입니다. 아니면 좀 더 친숙한 HTML 측면에서 기본 WordPress(+ PHP) 프로그래밍을 배우고 싶을 수도 있습니다.
당신이 오늘 여기에 있는 이유가 무엇이든, 이 WordPress 튜토리얼은 HTML에서 WordPress 테마를 만드는 기본 사항을 소개합니다. 이 가이드에 따라 처음부터 테마를 만들거나 Github로 가서 '빈 캔버스'를 제공하는 WPExplorer 시작 테마를 다운로드하여 시작하는 데 필요한 모든 템플릿 파일과 코드가 포함된 테마를 만들 수 있습니다. 따라서 코드를 읽어서 배우는 사람들 중 하나라면 시작 테마를 다운로드하고 가이드를 건너뛰고 어떻게 작동하는지 확인하십시오. 그렇지 않으면 코드 편집기(저는 Notepad++ 또는 SublimeText를 사용하고 권장합니다)와 브라우저를 준비하세요. , 그런 다음 이 간단한 가이드를 끝까지 따르십시오.
WordPress 테마 이름 지정
먼저, 테마에 고유한 이름을 지정해야 합니다. 이는 웹사이트 전용 테마를 구축하는 경우에는 필요하지 않습니다. 그럼에도 불구하고 설치 시 쉽게 식별할 수 있도록 테마 이름을 지정해야 합니다.
이 시점에서의 일반적인 가정:
- index.html과 CSS 스타일시트가 준비되었습니다.
- 하나 이상의 테마가 포함된 작동 중인 WordPress 설치가 있습니다. 스물넷
- 새로운 WordPress 테마를 저장할 테마 폴더를 이미 만들었습니다 ?
WordPress 테마 이름 지정으로 돌아가 보겠습니다. 코드 편집기를 열고 스타일시트의 내용을 새 파일에 복사하여 붙여넣고 테마 폴더에 style.css로 저장합니다. 새로 생성된 style.css 맨 위에 다음 정보를 추가합니다.
/*
Theme Name: Your theme's name
Theme URI: Your theme's URL
Description: A brief description of your theme
Version: 1.0 or any other version you want
Author: Your name or WordPress.org's username
Author URI: Your web address
Tags: Tags to locate your theme in the WordPress theme repository
*/(/*…*/) 주석 태그를 생략하지 마세요. 변경사항을 저장합니다. 이 정보는 WordPress에 테마 이름, 작성자 및 이와 같은 무료 항목을 알려줍니다. 중요한 부분은 테마 이름으로, 이를 통해 WP 대시보드를 통해 테마를 선택하고 활성화할 수 있습니다.
HTML 템플릿을 PHP 파일로 나누기
이 튜토리얼에서는 HTML 템플릿이 머리글, 콘텐츠, 사이드바, 바닥글 등 왼쪽에서 오른쪽으로 정렬되어 있다고 가정합니다. 디자인이 다른 경우 코드를 약간 조작해야 할 수도 있습니다. 재미있고 정말 쉽습니다.
다음 단계에서는 4개의 PHP 파일을 만드는 작업이 포함됩니다. 코드 편집기를 사용하여 index.php, header.php, sidebar.php 및 footer.php를 생성하고 테마 폴더에 저장합니다. 이 시점에서는 모든 파일이 비어 있으므로 아무 작업도 수행하지 않을 것으로 예상합니다. 설명을 위해 다음 index.html 및 CSS 스타일시트 파일을 사용하고 있습니다.
INDEX.HTML
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>How To Convert HTML Template to WordPress Theme - WPExplorer</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css"/>
</head>
<body>
<div id="wrap">
<header class="header">
<p>This is header section. Put your logo and other details here.</p>
</header><!-- .header -->
<div class="content">
<p>This is the main content area.</p>
</div><!-- .content -->
<div class="sidebar">
<p>This is the side bar</p>
</div><!-- .sidebar -->
<footer class="footer">
<p>And this is the footer.</p>
</footer><!-- .footer -->
</div><!-- #wrap -->
</body>
</html>CSS 스타일시트
#wrap{margin: 0 auto; width:95%; margin-top:-10px; height:100%;}
.header{width:99.8%; border:1px solid #999;height:135px;}
.content{width:70%; border:1px solid #999;margin-top:5px;}
.sidebar{float:right; margin-top:-54px;width:29%; border:1px solid #999;}
.footer{width:99.8%;border:1px solid #999;margin-top:10px;}작업할 내용이 없으면 두 코드를 모두 가져올 수 있습니다. 코드 편집기에 복사하여 붙여넣고 저장한 후 방금 언급한 4개의 PHP 파일을 만들고 다음 부분을 준비하세요. 새로 생성된(그리고 비어 있는) header.php를 엽니다. 기존 WordPress 설치에 로그인하고 Appearance –>> Editor 로 이동하여 header.php를 엽니다. <head> 태그 사이에 있는 모든 코드를 복사하여 header.php 파일에 붙여넣습니다. 다음은 Twenty Fourteen 테마의 header.php 파일에서 얻은 코드입니다.
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>그런 다음 index.html 파일을 열고 아래와 같이 헤더 코드(예:
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>
<body>
<header class="header">
<p>This is header section. Put your logo and other details here.</p>
</header>그런 다음 추가하세요…
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />...header.php 파일의 <head> 태그 사이에 스타일시트를 연결하세요. 위에 표시된 대로 header.php에 <html> 및 <body> 여는 태그를 넣는 것도 잊지 마세요. 모든 변경 사항을 저장합니다.
두 번째 섹션(예:
<?php get_header(); ?>… 맨 위에 그리고 …
<?php get_sidebar(); ?>
<?php get_footer(); ?>…완전히 바닥까지. 이 세 줄은 header.php, sidebar.php 및 footer.php(순서대로)를 가져와서 코드를 다시 통합하는 index.php에 표시합니다. 모든 변경 사항을 저장합니다. 이 시점에서 index.php 파일은 다음과 같아야 합니다:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>그런 다음 index.html의 사이드바 및 바닥글 섹션 내용을 각각 sidebar.php 및 footer.php에 복사합니다.
게시물 추가
귀하의 HTML 템플릿이 WordPress 테마로 바뀌려고 합니다. 게시물을 추가하기만 하면 됩니다. 블로그에 게시물이 있는 경우 맞춤 제작된 "HTML-to-WordPress" 테마에 해당 게시물을 어떻게 표시하시겠습니까? 루프라고 알려진 특별한 유형의 PHP 함수를 사용합니다. The Loop는 게시물과 댓글을 어디에 배치하든 표시하는 특수한 코드일 뿐입니다.
이제 index.php 템플릿의 콘텐츠 섹션에 게시물을 표시하려면
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-header">
<div class="date"><?php the_time( 'M j y' ); ?></div>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="author"><?php the_author(); ?></div>
</div><!--.post-header-->
<div class="entry clear">
<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php edit_post_link(); ?>
<?php wp_link_pages(); ?>
</div><!--. entry-->
<footer class="post-footer">
<div class="comments"><?php comments_popup_link( 'Leave a Comment', '1 Comment', '% Comments' ); ?></div>
</footer><!--.post-footer-->
</div><!-- .post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<nav class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</nav><!--.navigation-->
<?php else : ?>
<?php endif; ?>
</div><!--.content-->그러면 귀하의 게시물이 처리됩니다. ABC처럼 쉽습니다. 이 시점에서(그리고 이 튜토리얼에 제공된 샘플 파일을 사용하여) header.php는 다음과 같아야 합니다.
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>sidebar.php는 다음과 같아야 합니다:
<?php dynamic_sidebar( 'sidebar' ); ?>footer.php는 다음과 같아야 합니다:
<footer class="footer">
<p>And this is the footer</p>
</footer>
<?php wp_footer(); // Crucial core hook! ?>
</body>
</html>바닥글에서 닫는
