Ver3.0 ๐ WordPress ํ๋ฌ๊ทธ์ธ & ํ ๋ง ๊ฐ๋ฐ ์๋ฒฝ ๊ฐ์ด๋: ์ปค์คํ ํฌ์คํธ ํ์ ์ผ๋ก ๋๋ง์ ์น์ฌ์ดํธ ๋ง๋ค๊ธฐ

๐ WordPress ํ๋ฌ๊ทธ์ธ & ํ ๋ง ๊ฐ๋ฐ ์๋ฒฝ ๊ฐ์ด๋: ์ปค์คํ ํฌ์คํธ ํ์ ์ผ๋ก ๋๋ง์ ์น์ฌ์ดํธ ๋ง๋ค๊ธฐ
PHP ๊ธฐ๋ฐ WordPress ๊ฐ๋ฐ์ ๋ชจ๋ ๊ฒ, ์น๊ตฌ์ฒ๋ผ ์ฝ๊ฒ ์๋ ค๋๋ฆฝ๋๋ค!
๐ ์๋
! ์ค๋์ WordPress ๊ฐ๋ฐ์ ํต์ฌ์ด๋ผ๊ณ ํ ์ ์๋ ํ๋ฌ๊ทธ์ธ๊ณผ ํ
๋ง ๊ฐ๋ฐ, ๊ทธ๋ฆฌ๊ณ ์ปค์คํ
ํฌ์คํธ ํ์
ํ์ฉ๋ฒ์ ๋ํด ์ด์ผ๊ธฐํด๋ณผ๊ฒ. ํน์ WordPress๋ก ๋ธ๋ก๊ทธ๋ง ์ด์ํด๋ดค๋ค๋ฉด, ์ด ๊ธ์ ์ฝ๊ณ ๋๋ฉด ์์ ํ ์๋ก์ด ์ธ๊ณ๊ฐ ์ด๋ฆด ๊ฑฐ์ผ! ๐
WordPress๋ ์ ์ธ๊ณ ์น์ฌ์ดํธ์ ์ฝ 43%๋ฅผ ์ฐจ์งํ๋ ๊ฑฐ๋ํ ํ๋ซํผ์ด์ผ. ๋จ์ํ ๋ธ๋ก๊ทธ ๋๊ตฌ๋ฅผ ๋์ด์ ์ผํ๋ชฐ, ํฌํธํด๋ฆฌ์ค, ํ์์ ์ฌ์ดํธ ๋ฑ ๋ฌด์์ด๋ ๋ง๋ค ์ ์๋ ๊ฐ๋ ฅํ CMS(Content Management System)๋ก ๋ฐ์ ํ์ง. ๊ทธ ๋น๋ฐ์ ๋ฐ๋ก PHP ๊ธฐ๋ฐ์ ์ ์ฐํ ํ์ฅ์ฑ์ ์์ด!
๐ฏ WordPress ๊ฐ๋ฐ ํ๊ฒฝ ์ดํดํ๊ธฐ
WordPress ๊ฐ๋ฐ์ ์์ํ๊ธฐ ์ ์, ๋จผ์ WordPress๊ฐ ์ด๋ป๊ฒ ์๋ํ๋์ง ์ดํดํด์ผ ํด. WordPress๋ PHP๋ก ์์ฑ๋ ์คํ์์ค ์ํํธ์จ์ด์ผ. MySQL ๋๋ MariaDB ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉํ๊ณ , ํ๋ก ํธ์๋๋ HTML, CSS, JavaScript๋ก ๊ตฌ์ฑ๋์ง.
WordPress์ ํต์ฌ ๊ตฌ์กฐ๋ ํฌ๊ฒ ์ธ ๊ฐ์ง๋ก ๋๋ ์ ์์ด:
๐ WordPress ํต์ฌ ํ์ผ ๊ตฌ์กฐ
1. wp-admin/ - ๊ด๋ฆฌ์ ๋์๋ณด๋ ๊ด๋ จ ํ์ผ๋ค
2. wp-content/ - ํ
๋ง, ํ๋ฌ๊ทธ์ธ, ์
๋ก๋ ํ์ผ์ด ์ ์ฅ๋๋ ๊ณณ (์ฐ๋ฆฌ๊ฐ ์ฃผ๋ก ์์
ํ ๊ณต๊ฐ!)
3. wp-includes/ - WordPress ์ฝ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํจ์๋ค
์ฐ๋ฆฌ๊ฐ ๊ฐ๋ฐํ ๋๋ ์ฃผ๋ก wp-content ํด๋ ์์์ ์์
ํ๊ฒ ๋ผ. ์ฌ๊ธฐ์ themes ํด๋์ plugins ํด๋๊ฐ ์๊ฑฐ๋ !
๐ก ๊ฐ๋ฐ ํ๊ฒฝ ์ธํ ํ ๋ก์ปฌ ๊ฐ๋ฐ ํ๊ฒฝ์ผ๋ก๋ XAMPP, MAMP, Local by Flywheel ๊ฐ์ ๋๊ตฌ๋ค์ ์ถ์ฒํด. ํนํ Local by Flywheel์ WordPress ์ ์ฉ์ผ๋ก ๋ง๋ค์ด์ ธ์ ์ด๋ณด์๋ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์์ด. ํด๋ฆญ ๋ช ๋ฒ์ด๋ฉด ๋ก์ปฌ WordPress ์ฌ์ดํธ๊ฐ ๋๋ฑ ๋ง๋ค์ด์ง๊ฑฐ๋ !
๐จ WordPress ํ ๋ง ๊ฐ๋ฐ ์์ํ๊ธฐ
ํ ๋ง๋ WordPress ์ฌ์ดํธ์ ์ธ๊ด๊ณผ ๋ ์ด์์์ ๊ฒฐ์ ํ๋ ํ์ผ๋ค์ ๋ชจ์์ด์ผ. ์ต์ํ์ ํ ๋ง๋ฅผ ๋ง๋ค๋ ค๋ฉด ๋จ ๋ ๊ฐ์ ํ์ผ๋ง ์์ผ๋ฉด ๋ผ. ๋๋์ง? ๐ฎ
๐ ์ต์ ํ
๋ง ๊ตฌ์ฑ ์์
1. style.css - ํ
๋ง ์ ๋ณด์ ์คํ์ผ์ํธ
2. index.php - ๋ฉ์ธ ํ
ํ๋ฆฟ ํ์ผ
๋ฌผ๋ก ์ค์ ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ ํ
๋ง๋ฅผ ๋ง๋ค๋ ค๋ฉด ๋ ๋ง์ ํ์ผ์ด ํ์ํ์ง๋ง, ์ด ๋ ํ์ผ๋ง์ผ๋ก๋ WordPress๊ฐ ํ
๋ง๋ก ์ธ์ํ๋ค๋ ๊ฒ ์ค์ํด!
style.css ์์ฑํ๊ธฐ
ํ ๋ง์ style.css ํ์ผ ๋งจ ์์๋ ํน๋ณํ ์ฃผ์ ํ์์ผ๋ก ํ ๋ง ์ ๋ณด๋ฅผ ์์ฑํด์ผ ํด. ์ด๊ฑธ "ํ ๋ง ํค๋"๋ผ๊ณ ๋ถ๋ฅด์ง:
/*
Theme Name: My Awesome Theme
Theme URI: https://www.jaenung.net/my-theme
Author: Your Name
Author URI: https://www.jaenung.net
Description: ๋๋ง์ ๋ฉ์ง WordPress ํ
๋ง
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: my-awesome-theme
Tags: blog, custom-menu, featured-images
*/
/* ์ฌ๊ธฐ๋ถํฐ ์ค์ CSS ์คํ์ผ ์์ฑ */
body {
font-family: 'Noto Sans KR', sans-serif;
line-height: 1.6;
color: #333;
}
โ ๏ธ ์ฃผ์์ฌํญ Theme Name์ ํ์ ํญ๋ชฉ์ด์ผ! ์ด๊ฒ ์์ผ๋ฉด WordPress๊ฐ ํ ๋ง๋ก ์ธ์ํ์ง ๋ชปํด. ๋๋จธ์ง ํญ๋ชฉ๋ค์ ์ ํ์ฌํญ์ด์ง๋ง, ํ ๋ง๋ฅผ ๋ฐฐํฌํ๊ฑฐ๋ ๊ด๋ฆฌํ๋ ค๋ฉด ๋ชจ๋ ์์ฑํ๋ ๊ฒ ์ข์.
functions.php - ํ ๋ง์ ๋๋
functions.php๋ ํ ๋ง์ ๊ธฐ๋ฅ์ ํ์ฅํ๋ ํต์ฌ ํ์ผ์ด์ผ. ์ฌ๊ธฐ์ WordPress์ ๋ค์ํ ํ (Hook)์ ์ฌ์ฉํด์ ๊ธฐ๋ฅ์ ์ถ๊ฐํ ์ ์์ด. ์ค์ ์์ ๋ฅผ ๋ณด๋ฉด์ ์ดํดํด๋ณด์:
<?php
// ํ
๋ง ์ง์ ๊ธฐ๋ฅ ํ์ฑํ
function my_theme_setup() {
// ํฌ์คํธ ์ธ๋ค์ผ(Featured Image) ์ง์
add_theme_support('post-thumbnails');
// ์๋ ํผ๋ ๋งํฌ
add_theme_support('automatic-feed-links');
// HTML5 ๋งํฌ์
์ง์
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption'
));
// ํ์ดํ ํ๊ทธ ์ง์
add_theme_support('title-tag');
// ์ปค์คํ
๋ก๊ณ
add_theme_support('custom-logo', array(
'height' => 100,
'width' => 400,
'flex-height' => true,
'flex-width' => true
));
// ๋ค๋น๊ฒ์ด์
๋ฉ๋ด ๋ฑ๋ก
register_nav_menus(array(
'primary' => '๋ฉ์ธ ๋ฉ๋ด',
'footer' => 'ํธํฐ ๋ฉ๋ด'
));
}
add_action('after_setup_theme', 'my_theme_setup');
// ์คํ์ผ์ํธ์ ์คํฌ๋ฆฝํธ ๋ก๋
function my_theme_scripts() {
// ๋ฉ์ธ ์คํ์ผ์ํธ
wp_enqueue_style('main-style', get_stylesheet_uri());
// Google Fonts
wp_enqueue_style('google-fonts',
'https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700&display=swap');
// jQuery (WordPress ๋ด์ฅ)
wp_enqueue_script('jquery');
// ์ปค์คํ
์คํฌ๋ฆฝํธ
wp_enqueue_script('main-script',
get_template_directory_uri() . '/js/main.js',
array('jquery'),
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'my_theme_scripts');
// ์์ ฏ ์์ญ ๋ฑ๋ก
function my_theme_widgets_init() {
register_sidebar(array(
'name' => '์ฌ์ด๋๋ฐ',
'id' => 'sidebar-1',
'description' => '๋ฉ์ธ ์ฌ์ด๋๋ฐ ์์ ฏ ์์ญ',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
}
add_action('widgets_init', 'my_theme_widgets_init');
?>
๐ก WordPress ํ
(Hook) ์ดํดํ๊ธฐ
WordPress์ ํ
์ ํฌ๊ฒ ๋ ๊ฐ์ง์ผ:
1. Action Hook - ํน์ ์์ ์ ํจ์๋ฅผ ์คํ (add_action ์ฌ์ฉ)
2. Filter Hook - ๋ฐ์ดํฐ๋ฅผ ์์ ํด์ ๋ฐํ (add_filter ์ฌ์ฉ)
์ ์ฝ๋์์ 'after_setup_theme', 'wp_enqueue_scripts', 'widgets_init' ๊ฐ์ ๊ฒ ๋ฐ๋ก ์ก์
ํ
์ด์ผ. WordPress๊ฐ ์คํ๋๋ ๊ณผ์ ์์ ํน์ ์์ ์ ์ฐ๋ฆฌ๊ฐ ๋ง๋ ํจ์๋ฅผ ๋ผ์๋ฃ๋ ๊ฑฐ์ง!
๐ WordPress ํ๋ฌ๊ทธ์ธ ๊ฐ๋ฐ์ ์ธ๊ณ
ํ๋ฌ๊ทธ์ธ์ WordPress์ ๊ธฐ๋ฅ์ ํ์ฅํ๋ ๋ ๋ฆฝ์ ์ธ ๋ชจ๋์ด์ผ. ํ ๋ง๊ฐ "์ธ๊ด"์ ๋ด๋นํ๋ค๋ฉด, ํ๋ฌ๊ทธ์ธ์ "๊ธฐ๋ฅ"์ ๋ด๋นํ์ง. ์๋ฅผ ๋ค์ด ๋ฌธ์ ํผ, SEO ์ต์ ํ, ๋ณด์ ๊ฐํ, ์์ ๋ฏธ๋์ด ์ฐ๋ ๋ฑ ๋ค์ํ ๊ธฐ๋ฅ์ ํ๋ฌ๊ทธ์ธ์ผ๋ก ์ถ๊ฐํ ์ ์์ด! ๐ฎ
ํ๋ฌ๊ทธ์ธ์ ๊ธฐ๋ณธ ๊ตฌ์กฐ
๊ฐ์ฅ ๊ฐ๋จํ ํ๋ฌ๊ทธ์ธ์ ๋จ ํ๋์ PHP ํ์ผ๋ก๋ ๋ง๋ค ์ ์์ด. wp-content/plugins/ ํด๋์ ์ ํด๋๋ฅผ ๋ง๋ค๊ณ , ๊ทธ ์์ PHP ํ์ผ์ ์์ฑํ๋ฉด ๋ผ:
<?php
/*
Plugin Name: My First Plugin
Plugin URI: https://www.jaenung.net/my-plugin
Description: ๋ด๊ฐ ๋ง๋ ์ฒซ ๋ฒ์งธ WordPress ํ๋ฌ๊ทธ์ธ
Version: 1.0.0
Author: Your Name
Author URI: https://www.jaenung.net
License: GPL2
Text Domain: my-first-plugin
*/
// WordPress ์ธ๋ถ์์ ์ง์ ์ ๊ทผ ๋ฐฉ์ง
if (!defined('ABSPATH')) {
exit;
}
// ํ๋ฌ๊ทธ์ธ ํ์ฑํ ์ ์คํ๋ ํจ์
function mfp_activate() {
// ์ต์
์ถ๊ฐ
add_option('mfp_version', '1.0.0');
// ์ปค์คํ
๋ฐ์ดํฐ๋ฒ ์ด์ค ํ
์ด๋ธ ์์ฑ ๋ฑ
global $wpdb;
$table_name = $wpdb->prefix . 'my_custom_table';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook(__FILE__, 'mfp_activate');
// ํ๋ฌ๊ทธ์ธ ๋นํ์ฑํ ์ ์คํ๋ ํจ์
function mfp_deactivate() {
// ์์ ๋ฐ์ดํฐ ์ ๋ฆฌ ๋ฑ
delete_option('mfp_temp_data');
}
register_deactivation_hook(__FILE__, 'mfp_deactivate');
// ํ๋ฌ๊ทธ์ธ ์ญ์ ์ ์คํ๋ ํจ์
function mfp_uninstall() {
// ๋ชจ๋ ๋ฐ์ดํฐ ์ญ์
delete_option('mfp_version');
global $wpdb;
$table_name = $wpdb->prefix . 'my_custom_table';
$wpdb->query("DROP TABLE IF EXISTS $table_name");
}
register_uninstall_hook(__FILE__, 'mfp_uninstall');
// ์ค์ ํ๋ฌ๊ทธ์ธ ๊ธฐ๋ฅ ๊ตฌํ
function mfp_add_custom_content($content) {
if (is_single()) {
$custom_content = '<div class="custom-notice">์ด ๊ธ์ด ๋์์ด ๋์
จ๋์?</div>';
$content .= $custom_content;
}
return $content;
}
add_filter('the_content', 'mfp_add_custom_content');
// ๊ด๋ฆฌ์ ๋ฉ๋ด ์ถ๊ฐ
function mfp_admin_menu() {
add_menu_page(
'My Plugin Settings', // ํ์ด์ง ํ์ดํ
'My Plugin', // ๋ฉ๋ด ์ด๋ฆ
'manage_options', // ๊ถํ
'my-plugin-settings', // ๋ฉ๋ด ์ฌ๋ฌ๊ทธ
'mfp_settings_page', // ์ฝ๋ฐฑ ํจ์
'dashicons-admin-generic', // ์์ด์ฝ
30 // ๋ฉ๋ด ์์น
);
}
add_action('admin_menu', 'mfp_admin_menu');
// ์ค์ ํ์ด์ง HTML
function mfp_settings_page() {
?>
<div class="wrap">
<h1>My Plugin Settings</h1>
<form method="post" action="options.php">
<?php
settings_fields('mfp_settings_group');
do_settings_sections('my-plugin-settings');
submit_button();
?>
</form>
</div>
<?php
}
?>
๐ฏ ํ๋ฌ๊ทธ์ธ ๊ฐ๋ฐ ํต์ฌ ํฌ์ธํธ
1. ๋ณด์ - ํญ์ ABSPATH ์ฒดํฌ๋ก ์ง์ ์ ๊ทผ์ ๋ง์์ผ ํด
2. ๋ค์์คํ์ด์ค - ํจ์๋ช
์ ๊ณ ์ ํ ์ ๋์ฌ๋ฅผ ๋ถ์ฌ์ ์ถฉ๋ ๋ฐฉ์ง
3. ํ
ํ์ฉ - WordPress์ ์ก์
๊ณผ ํํฐ๋ฅผ ์ ๊ทน ํ์ฉ
4. ๋ฐ์ดํฐ๋ฒ ์ด์ค - $wpdb ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด์ ์์ ํ๊ฒ ์ฟผ๋ฆฌ ์คํ
5. ๊ตญ์ ํ - Text Domain์ ์ค์ ํด์ ๋ค๊ตญ์ด ์ง์ ์ค๋น
๐ช ์ปค์คํ ํฌ์คํธ ํ์ (Custom Post Type) ๋ง์คํฐํ๊ธฐ
์, ์ด์ ์ค๋์ ํ์ด๋ผ์ดํธ์ธ ์ปค์คํ
ํฌ์คํธ ํ์
์ ๋ํด ์์๋ณด์! ๐
WordPress๋ ๊ธฐ๋ณธ์ ์ผ๋ก 'ํฌ์คํธ(Post)'์ 'ํ์ด์ง(Page)'๋ผ๋ ๋ ๊ฐ์ง ์ฝํ
์ธ ํ์
์ ์ ๊ณตํด. ํ์ง๋ง ํฌํธํด๋ฆฌ์ค, ์ ํ, ์ด๋ฒคํธ, ํ ๋ฉค๋ฒ ์๊ฐ ๊ฐ์ ํน๋ณํ ์ฝํ
์ธ ๋ฅผ ๊ด๋ฆฌํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ ๊น? ๋ฐ๋ก ์ปค์คํ
ํฌ์คํธ ํ์
์ ๋ง๋ค๋ฉด ๋ผ!
์ปค์คํ ํฌ์คํธ ํ์ ์ด ํ์ํ ์ด์
๐ ์ค์ ํ์ฉ ์ฌ๋ก
1. ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ - 'ํ๋ก์ ํธ' ํฌ์คํธ ํ์
์ผ๋ก ์์
๋ฌผ ๊ด๋ฆฌ
2. ์ผํ๋ชฐ - '์ ํ' ํฌ์คํธ ํ์
์ผ๋ก ์ํ ์ ๋ณด ๊ด๋ฆฌ
3. ๋ถ๋์ฐ ์ฌ์ดํธ - '๋งค๋ฌผ' ํฌ์คํธ ํ์
์ผ๋ก ๋ถ๋์ฐ ์ ๋ณด ๊ด๋ฆฌ
4. ๋ ์คํ ๋ ์ฌ์ดํธ - '๋ฉ๋ด' ํฌ์คํธ ํ์
์ผ๋ก ์์ ๋ฉ๋ด ๊ด๋ฆฌ
5. ์ด๋ฒคํธ ์ฌ์ดํธ - '์ด๋ฒคํธ' ํฌ์คํธ ํ์
์ผ๋ก ํ์ฌ ์ ๋ณด ๊ด๋ฆฌ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ๋ '์ฌ๋ฅ', '์๋น์ค', '๊ฐ์' ๊ฐ์ ์ปค์คํ
ํฌ์คํธ ํ์
์ ํ์ฉํด์ ๋ค์ํ ์ฝํ
์ธ ๋ฅผ ์ฒด๊ณ์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์์ด!
์ปค์คํ ํฌ์คํธ ํ์ ๋ฑ๋กํ๊ธฐ
์ปค์คํ ํฌ์คํธ ํ์ ์ register_post_type() ํจ์๋ก ๋ฑ๋กํด. ์ค์ ์์ ๋ฅผ ๋ณด๋ฉด์ ํ๋ํ๋ ์ดํดํด๋ณด์:
<?php
function create_portfolio_post_type() {
$labels = array(
'name' => 'ํฌํธํด๋ฆฌ์ค',
'singular_name' => 'ํฌํธํด๋ฆฌ์ค',
'menu_name' => 'ํฌํธํด๋ฆฌ์ค',
'add_new' => '์ ํ๋ก์ ํธ ์ถ๊ฐ',
'add_new_item' => '์ ํฌํธํด๋ฆฌ์ค ์ถ๊ฐ',
'edit_item' => 'ํฌํธํด๋ฆฌ์ค ์์ ',
'new_item' => '์ ํฌํธํด๋ฆฌ์ค',
'view_item' => 'ํฌํธํด๋ฆฌ์ค ๋ณด๊ธฐ',
'search_items' => 'ํฌํธํด๋ฆฌ์ค ๊ฒ์',
'not_found' => 'ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค',
'not_found_in_trash' => 'ํด์งํต์ ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค',
'all_items' => '๋ชจ๋ ํฌํธํด๋ฆฌ์ค',
'archives' => 'ํฌํธํด๋ฆฌ์ค ์์นด์ด๋ธ',
'insert_into_item' => 'ํฌํธํด๋ฆฌ์ค์ ์ฝ์
',
'uploaded_to_this_item' => '์ด ํฌํธํด๋ฆฌ์ค์ ์
๋ก๋๋จ',
'featured_image' => '๋ํ ์ด๋ฏธ์ง',
'set_featured_image' => '๋ํ ์ด๋ฏธ์ง ์ค์ ',
'remove_featured_image' => '๋ํ ์ด๋ฏธ์ง ์ ๊ฑฐ',
'use_featured_image' => '๋ํ ์ด๋ฏธ์ง๋ก ์ฌ์ฉ'
);
$args = array(
'labels' => $labels,
'public' => true, // ๊ณต๊ฐ ํฌ์คํธ ํ์
'publicly_queryable' => true, // ํ๋ก ํธ์๋์์ ์ฟผ๋ฆฌ ๊ฐ๋ฅ
'show_ui' => true, // ๊ด๋ฆฌ์ UI ํ์
'show_in_menu' => true, // ๊ด๋ฆฌ์ ๋ฉ๋ด์ ํ์
'show_in_nav_menus' => true, // ๋ค๋น๊ฒ์ด์
๋ฉ๋ด์์ ์ ํ ๊ฐ๋ฅ
'show_in_admin_bar' => true, // ๊ด๋ฆฌ์ ๋ฐ์ ํ์
'show_in_rest' => true, // REST API ์ง์ (๋ธ๋ก ์๋ํฐ ํ์)
'query_var' => true, // ์ฟผ๋ฆฌ ๋ณ์ ํ์ฑํ
'rewrite' => array(
'slug' => 'portfolio', // URL ์ฌ๋ฌ๊ทธ
'with_front' => false // ํผ๋จธ๋งํฌ ๊ตฌ์กฐ ์๋ถ๋ถ ์ ๊ฑฐ
),
'capability_type' => 'post', // ๊ถํ ํ์
'has_archive' => true, // ์์นด์ด๋ธ ํ์ด์ง ํ์ฑํ
'hierarchical' => false, // ๊ณ์ธต ๊ตฌ์กฐ (false = ํฌ์คํธํ, true = ํ์ด์งํ)
'menu_position' => 5, // ๋ฉ๋ด ์์น
'menu_icon' => 'dashicons-portfolio', // ๋ฉ๋ด ์์ด์ฝ
'supports' => array( // ์ง์ ๊ธฐ๋ฅ
'title', // ์ ๋ชฉ
'editor', // ์๋ํฐ
'thumbnail', // ์ธ๋ค์ผ
'excerpt', // ๋ฐ์ท
'custom-fields', // ์ปค์คํ
ํ๋
'comments', // ๋๊ธ
'revisions', // ๋ฆฌ๋น์
'author', // ์์ฑ์
'page-attributes' // ํ์ด์ง ์์ฑ
),
'taxonomies' => array( // ์ฐ๊ฒฐํ ํ์๋
ธ๋ฏธ
'portfolio_category',
'portfolio_tag'
)
);
register_post_type('portfolio', $args);
}
add_action('init', 'create_portfolio_post_type');
?>
๐ก show_in_rest์ ์ค์์ฑ 'show_in_rest' => true๋ WordPress 5.0 ์ด์์์ ๋งค์ฐ ์ค์ํด! ์ด ์ต์ ์ true๋ก ์ค์ ํด์ผ Gutenberg ๋ธ๋ก ์๋ํฐ๋ฅผ ์ฌ์ฉํ ์ ์๊ฑฐ๋ . false๋ก ํ๋ฉด ํด๋์ ์๋ํฐ๋ง ์ฌ์ฉ ๊ฐ๋ฅํด. ๋ํ REST API๋ฅผ ํตํด ์ธ๋ถ ์ ํ๋ฆฌ์ผ์ด์ ์์๋ ๋ฐ์ดํฐ์ ์ ๊ทผํ ์ ์๊ฒ ๋ผ.
์ปค์คํ ํ์๋ ธ๋ฏธ(Custom Taxonomy) ์ถ๊ฐํ๊ธฐ
์ปค์คํ ํฌ์คํธ ํ์ ์ ๋ง๋ค์๋ค๋ฉด, ์ด์ ๋ถ๋ฅ ์ฒด๊ณ๋ ํ์ํ๊ฒ ์ง? ์ผ๋ฐ ํฌ์คํธ์ ์นดํ ๊ณ ๋ฆฌ์ ํ๊ทธ๊ฐ ์๋ฏ์ด, ์ปค์คํ ํฌ์คํธ ํ์ ์๋ ์ ์ฉ ๋ถ๋ฅ๋ฅผ ๋ง๋ค ์ ์์ด:
<?php
function create_portfolio_taxonomies() {
// ํฌํธํด๋ฆฌ์ค ์นดํ
๊ณ ๋ฆฌ (๊ณ์ธต ๊ตฌ์กฐ)
$category_labels = array(
'name' => 'ํฌํธํด๋ฆฌ์ค ์นดํ
๊ณ ๋ฆฌ',
'singular_name' => '์นดํ
๊ณ ๋ฆฌ',
'search_items' => '์นดํ
๊ณ ๋ฆฌ ๊ฒ์',
'all_items' => '๋ชจ๋ ์นดํ
๊ณ ๋ฆฌ',
'parent_item' => '์์ ์นดํ
๊ณ ๋ฆฌ',
'parent_item_colon' => '์์ ์นดํ
๊ณ ๋ฆฌ:',
'edit_item' => '์นดํ
๊ณ ๋ฆฌ ์์ ',
'update_item' => '์นดํ
๊ณ ๋ฆฌ ์
๋ฐ์ดํธ',
'add_new_item' => '์ ์นดํ
๊ณ ๋ฆฌ ์ถ๊ฐ',
'new_item_name' => '์ ์นดํ
๊ณ ๋ฆฌ ์ด๋ฆ',
'menu_name' => '์นดํ
๊ณ ๋ฆฌ'
);
$category_args = array(
'labels' => $category_labels,
'hierarchical' => true, // ๊ณ์ธต ๊ตฌ์กฐ (์นดํ
๊ณ ๋ฆฌ์ฒ๋ผ)
'public' => true,
'show_ui' => true,
'show_admin_column' => true, // ๊ด๋ฆฌ์ ๋ชฉ๋ก์ ์ปฌ๋ผ ํ์
'show_in_nav_menus' => true,
'show_in_rest' => true,
'show_tagcloud' => true,
'rewrite' => array(
'slug' => 'portfolio-category',
'with_front' => false,
'hierarchical' => true
)
);
register_taxonomy('portfolio_category', 'portfolio', $category_args);
// ํฌํธํด๋ฆฌ์ค ํ๊ทธ (๋น๊ณ์ธต ๊ตฌ์กฐ)
$tag_labels = array(
'name' => 'ํฌํธํด๋ฆฌ์ค ํ๊ทธ',
'singular_name' => 'ํ๊ทธ',
'search_items' => 'ํ๊ทธ ๊ฒ์',
'all_items' => '๋ชจ๋ ํ๊ทธ',
'edit_item' => 'ํ๊ทธ ์์ ',
'update_item' => 'ํ๊ทธ ์
๋ฐ์ดํธ',
'add_new_item' => '์ ํ๊ทธ ์ถ๊ฐ',
'new_item_name' => '์ ํ๊ทธ ์ด๋ฆ',
'menu_name' => 'ํ๊ทธ'
);
$tag_args = array(
'labels' => $tag_labels,
'hierarchical' => false, // ๋น๊ณ์ธต ๊ตฌ์กฐ (ํ๊ทธ์ฒ๋ผ)
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'show_tagcloud' => true,
'rewrite' => array(
'slug' => 'portfolio-tag',
'with_front' => false
)
);
register_taxonomy('portfolio_tag', 'portfolio', $tag_args);
}
add_action('init', 'create_portfolio_taxonomies');
?>
โ ๏ธ ํผ๋จธ๋งํฌ ์ฌ์ค์ ํ์! ์ปค์คํ ํฌ์คํธ ํ์ ์ด๋ ํ์๋ ธ๋ฏธ๋ฅผ ์๋ก ๋ฑ๋กํ ํ์๋ ๋ฐ๋์ ๊ด๋ฆฌ์ ํ์ด์ง์์ '์ค์ > ๊ณ ์ ์ฃผ์'๋ก ๊ฐ์ '๋ณ๊ฒฝ์ฌํญ ์ ์ฅ' ๋ฒํผ์ ๋๋ฌ์ค์ผ ํด. ๊ทธ๋์ผ rewrite ๊ท์น์ด ์ ๋๋ก ์ ์ฉ๋ผ์ 404 ์๋ฌ๊ฐ ๋ฐ์ํ์ง ์์!
๐ ๏ธ ์ปค์คํ ๋ฉํ๋ฐ์ค์ ํ๋ ์ถ๊ฐํ๊ธฐ
์ปค์คํ
ํฌ์คํธ ํ์
์ ๋ง๋ค์๋ค๋ฉด, ์ด์ ์ถ๊ฐ ์ ๋ณด๋ฅผ ์
๋ ฅ๋ฐ์ ์ปค์คํ
ํ๋๊ฐ ํ์ํด. ์๋ฅผ ๋ค์ด ํฌํธํด๋ฆฌ์ค๋ผ๋ฉด 'ํด๋ผ์ด์ธํธ๋ช
', 'ํ๋ก์ ํธ ๊ธฐ๊ฐ', '์ฌ์ฉ ๊ธฐ์ ', 'ํ๋ก์ ํธ URL' ๊ฐ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ณ ์ถ๊ฒ ์ง?
WordPress์์๋ ๋ฉํ๋ฐ์ค(Metabox)๋ฅผ ํตํด ์ด๋ฐ ์ปค์คํ
ํ๋๋ฅผ ์ถ๊ฐํ ์ ์์ด! ๐จ
๋ฉํ๋ฐ์ค ์์ฑํ๊ธฐ
<?php
// ๋ฉํ๋ฐ์ค ์ถ๊ฐ
function portfolio_add_meta_boxes() {
add_meta_box(
'portfolio_details', // ๋ฉํ๋ฐ์ค ID
'ํ๋ก์ ํธ ์์ธ ์ ๋ณด', // ๋ฉํ๋ฐ์ค ์ ๋ชฉ
'portfolio_meta_box_callback', // ์ฝ๋ฐฑ ํจ์
'portfolio', // ํฌ์คํธ ํ์
'normal', // ์์น (normal, side, advanced)
'high' // ์ฐ์ ์์ (high, low, default)
);
}
add_action('add_meta_boxes', 'portfolio_add_meta_boxes');
// ๋ฉํ๋ฐ์ค HTML ์ถ๋ ฅ
function portfolio_meta_box_callback($post) {
// nonce ํ๋ ์ถ๊ฐ (๋ณด์)
wp_nonce_field('portfolio_meta_box', 'portfolio_meta_box_nonce');
// ์ ์ฅ๋ ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
$client = get_post_meta($post->ID, '_portfolio_client', true);
$duration = get_post_meta($post->ID, '_portfolio_duration', true);
$technologies = get_post_meta($post->ID, '_portfolio_technologies', true);
$project_url = get_post_meta($post->ID, '_portfolio_url', true);
$completion_date = get_post_meta($post->ID, '_portfolio_completion_date', true);
?>
<div style="padding: 15px;">
<p>
<label for="portfolio_client" style="display: inline-block; width: 150px; font-weight: bold;">
ํด๋ผ์ด์ธํธ:
</label>
<input type="text" id="portfolio_client" name="portfolio_client"
value="<?php echo esc_attr($client); ?>"
style="width: 60%;" />
</p>
<p>
<label for="portfolio_duration" style="display: inline-block; width: 150px; font-weight: bold;">
ํ๋ก์ ํธ ๊ธฐ๊ฐ:
</label>
<input type="text" id="portfolio_duration" name="portfolio_duration"
value="<?php echo esc_attr($duration); ?>"
placeholder="์: 3๊ฐ์"
style="width: 60%;" />
</p>
<p>
<label for="portfolio_technologies" style="display: inline-block; width: 150px; font-weight: bold;">
์ฌ์ฉ ๊ธฐ์ :
</label>
<input type="text" id="portfolio_technologies" name="portfolio_technologies"
value="<?php echo esc_attr($technologies); ?>"
placeholder="์: WordPress, PHP, JavaScript"
style="width: 60%;" />
</p>
<p>
<label for="portfolio_url" style="display: inline-block; width: 150px; font-weight: bold;">
ํ๋ก์ ํธ URL:
</label>
<input type="url" id="portfolio_url" name="portfolio_url"
value="<?php echo esc_url($project_url); ?>"
placeholder="https://example.com"
style="width: 60%;" />
</p>
<p>
<label for="portfolio_completion_date" style="display: inline-block; width: 150px; font-weight: bold;">
์๋ฃ์ผ:
</label>
<input type="date" id="portfolio_completion_date" name="portfolio_completion_date"
value="<?php echo esc_attr($completion_date); ?>"
style="width: 60%;" />
</p>
</div>
<?php
}
// ๋ฉํ๋ฐ์ค ๋ฐ์ดํฐ ์ ์ฅ
function portfolio_save_meta_box($post_id) {
// nonce ๊ฒ์ฆ
if (!isset($_POST['portfolio_meta_box_nonce'])) {
return;
}
if (!wp_verify_nonce($_POST['portfolio_meta_box_nonce'], 'portfolio_meta_box')) {
return;
}
// ์๋ ์ ์ฅ ์ ์คํ ๋ฐฉ์ง
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// ๊ถํ ํ์ธ
if (!current_user_can('edit_post', $post_id)) {
return;
}
// ๋ฐ์ดํฐ ์ ์ฅ
if (isset($_POST['portfolio_client'])) {
update_post_meta($post_id, '_portfolio_client',
sanitize_text_field($_POST['portfolio_client']));
}
if (isset($_POST['portfolio_duration'])) {
update_post_meta($post_id, '_portfolio_duration',
sanitize_text_field($_POST['portfolio_duration']));
}
if (isset($_POST['portfolio_technologies'])) {
update_post_meta($post_id, '_portfolio_technologies',
sanitize_text_field($_POST['portfolio_technologies']));
}
if (isset($_POST['portfolio_url'])) {
update_post_meta($post_id, '_portfolio_url',
esc_url_raw($_POST['portfolio_url']));
}
if (isset($_POST['portfolio_completion_date'])) {
update_post_meta($post_id, '_portfolio_completion_date',
sanitize_text_field($_POST['portfolio_completion_date']));
}
}
add_action('save_post_portfolio', 'portfolio_save_meta_box');
?>
๐ ๋ณด์ ์ฒดํฌ๋ฆฌ์คํธ
๋ฉํ๋ฐ์ค ์ ์ฅ ์ ๋ฐ๋์ ํ์ธํด์ผ ํ ๋ณด์ ์ฌํญ๋ค:
1. Nonce ๊ฒ์ฆ - CSRF ๊ณต๊ฒฉ ๋ฐฉ์ง
2. ๊ถํ ํ์ธ - current_user_can()์ผ๋ก ๊ถํ ์ฒดํฌ
3. ์๋ ์ ์ฅ ๋ฐฉ์ง - DOING_AUTOSAVE ์ฒดํฌ
4. ๋ฐ์ดํฐ ๊ฒ์ฆ - sanitize_text_field(), esc_url_raw() ๋ฑ์ผ๋ก ์
๋ ฅ๊ฐ ์ ์
5. ์ถ๋ ฅ ์ด์ค์ผ์ดํ - esc_attr(), esc_url() ๋ฑ์ผ๋ก XSS ๋ฐฉ์ง
Advanced Custom Fields (ACF) ํ๋ฌ๊ทธ์ธ ํ์ฉ
์ง์ ์ฝ๋ฉํ๋ ๊ฒ ๋ถ๋ด์ค๋ฝ๋ค๋ฉด, ACF ๊ฐ์ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ACF๋ GUI๋ก ์ฝ๊ฒ ์ปค์คํ ํ๋๋ฅผ ๋ง๋ค ์ ์๊ฒ ํด์ฃผ๊ฑฐ๋ ! ๐
๐ฏ ACF ์ฌ์ฉ์ ์ฅ์
1. ์ง๊ด์ ์ธ UI - ์ฝ๋ฉ ์์ด ํ๋ ์์ฑ
2. ๋ค์ํ ํ๋ ํ์
- ํ
์คํธ, ์ด๋ฏธ์ง, ๊ฐค๋ฌ๋ฆฌ, ๊ด๊ณ, ๋ฐ๋ณต ํ๋ ๋ฑ
3. ์กฐ๊ฑด๋ถ ๋ก์ง - ํน์ ์กฐ๊ฑด์์๋ง ํ๋ ํ์
4. ์์น ๊ท์น - ํน์ ํฌ์คํธ ํ์
, ํ
ํ๋ฆฟ, ์นดํ
๊ณ ๋ฆฌ์๋ง ์ ์ฉ
5. ํ๋ก ํธ์๋ ํผ - ์ฌ์ฉ์๊ฐ ์ง์ ๋ฐ์ดํฐ ์
๋ ฅ ๊ฐ๋ฅ
๋ฌด๋ฃ ๋ฒ์ ๋ ์ถฉ๋ถํ ๊ฐ๋ ฅํ์ง๋ง, Pro ๋ฒ์ ์ ๋ ๋ง์ ํ๋ ํ์
๊ณผ ๊ธฐ๋ฅ์ ์ ๊ณตํด!
๐ ์ปค์คํ ํฌ์คํธ ํ์ ํ ํ๋ฆฟ ๋ง๋ค๊ธฐ
์ปค์คํ ํฌ์คํธ ํ์ ์ ๋ฑ๋กํ๋ค๋ฉด, ์ด์ ํ๋ก ํธ์๋์์ ์ด๋ป๊ฒ ๋ณด์ฌ์ค์ง ๊ฒฐ์ ํด์ผ ํด. WordPress๋ ํ ํ๋ฆฟ ๊ณ์ธต ๊ตฌ์กฐ(Template Hierarchy)๋ฅผ ๋ฐ๋ผ์ ์๋์ผ๋ก ์ ์ ํ ํ ํ๋ฆฟ ํ์ผ์ ์ฐพ์!
ํ ํ๋ฆฟ ๊ณ์ธต ๊ตฌ์กฐ ์ดํดํ๊ธฐ
| ํ์ด์ง ํ์ | ํ ํ๋ฆฟ ํ์ผ ์ฐ์ ์์ | ์ค๋ช |
|---|---|---|
| ๋จ์ผ ํฌ์คํธ | single-portfolio.php โ single.php โ singular.php โ index.php | ๊ฐ๋ณ ํฌํธํด๋ฆฌ์ค ํ์ด์ง |
| ์์นด์ด๋ธ | archive-portfolio.php โ archive.php โ index.php | ํฌํธํด๋ฆฌ์ค ๋ชฉ๋ก ํ์ด์ง |
| ํ์๋ ธ๋ฏธ | taxonomy-portfolio_category.php โ taxonomy.php โ archive.php | ์นดํ ๊ณ ๋ฆฌ๋ณ ๋ชฉ๋ก |
| ํ์๋ ธ๋ฏธ ํ | taxonomy-portfolio_category-web.php โ taxonomy-portfolio_category.php | ํน์ ์นดํ ๊ณ ๋ฆฌ ๋ชฉ๋ก |
single-portfolio.php ๋ง๋ค๊ธฐ
๊ฐ๋ณ ํฌํธํด๋ฆฌ์ค ํ์ด์ง๋ฅผ ์ํ ํ ํ๋ฆฟ์ ๋ง๋ค์ด๋ณด์:
<?php
/**
* Template for displaying single portfolio items
*/
get_header(); ?>
<div class="portfolio-single-wrapper">
<?php while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- ํฌํธํด๋ฆฌ์ค ํค๋ -->
<header class="portfolio-header">
<h1 class="portfolio-title"><?php the_title(); ?></h1>
<?php if (has_post_thumbnail()) : ?>
<div class="portfolio-featured-image">
<?php the_post_thumbnail('large'); ?>
</div>
<?php endif; ?>
</header>
<!-- ํ๋ก์ ํธ ์ ๋ณด -->
<div class="portfolio-meta">
<?php
$client = get_post_meta(get_the_ID(), '_portfolio_client', true);
$duration = get_post_meta(get_the_ID(), '_portfolio_duration', true);
$technologies = get_post_meta(get_the_ID(), '_portfolio_technologies', true);
$project_url = get_post_meta(get_the_ID(), '_portfolio_url', true);
$completion_date = get_post_meta(get_the_ID(), '_portfolio_completion_date', true);
?>
<div class="project-info-grid">
<?php if ($client) : ?>
<div class="info-item">
<span class="info-label">ํด๋ผ์ด์ธํธ:</span>
<span class="info-value"><?php echo esc_html($client); ?></span>
</div>
<?php endif; ?>
<?php if ($duration) : ?>
<div class="info-item">
<span class="info-label">ํ๋ก์ ํธ ๊ธฐ๊ฐ:</span>
<span class="info-value"><?php echo esc_html($duration); ?></span>
</div>
<?php endif; ?>
<?php if ($technologies) : ?>
<div class="info-item">
<span class="info-label">์ฌ์ฉ ๊ธฐ์ :</span>
<span class="info-value"><?php echo esc_html($technologies); ?></span>
</div>
<?php endif; ?>
<?php if ($completion_date) : ?>
<div class="info-item">
<span class="info-label">์๋ฃ์ผ:</span>
<span class="info-value"><?php echo esc_html($completion_date); ?></span>
</div>
<?php endif; ?>
<?php if ($project_url) : ?>
<div class="info-item">
<span class="info-label">ํ๋ก์ ํธ URL:</span>
<span class="info-value">
<a href="<?php echo esc_url($project_url); ?>" target="_blank" rel="noopener">
์ฌ์ดํธ ๋ฐฉ๋ฌธํ๊ธฐ โ
</a>
</span>
</div>
<?php endif; ?>
</div>
</div>
<!-- ์นดํ
๊ณ ๋ฆฌ์ ํ๊ทธ -->
<div class="portfolio-taxonomies">
<?php
$categories = get_the_terms(get_the_ID(), 'portfolio_category');
if ($categories && !is_wp_error($categories)) :
?>
<div class="portfolio-categories">
<span class="tax-label">์นดํ
๊ณ ๋ฆฌ:</span>
<?php foreach ($categories as $category) : ?>
<a href="<?php echo esc_url(get_term_link($category)); ?>" class="category-badge">
<?php echo esc_html($category->name); ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
$tags = get_the_terms(get_the_ID(), 'portfolio_tag');
if ($tags && !is_wp_error($tags)) :
?>
<div class="portfolio-tags">
<span class="tax-label">ํ๊ทธ:</span>
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo esc_url(get_term_link($tag)); ?>" class="tag-badge">
#<?php echo esc_html($tag->name); ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- ๋ณธ๋ฌธ ๋ด์ฉ -->
<div class="portfolio-content">
<?php the_content(); ?>
</div>
<!-- ๋ค๋น๊ฒ์ด์
-->
<nav class="portfolio-navigation">
<div class="nav-previous">
<?php previous_post_link('%link', 'โ ์ด์ ํ๋ก์ ํธ', true, '', 'portfolio_category'); ?>
</div>
<div class="nav-next">
<?php next_post_link('%link', '๋ค์ ํ๋ก์ ํธ โ', true, '', 'portfolio_category'); ?>
</div>
</nav>
</article>
<?php endwhile; ?>
</div>
<?php get_footer(); ?>
archive-portfolio.php ๋ง๋ค๊ธฐ
ํฌํธํด๋ฆฌ์ค ๋ชฉ๋ก ํ์ด์ง ํ ํ๋ฆฟ๋ ๋ง๋ค์ด๋ณด์:
<?php
/**
* Template for displaying portfolio archive
*/
get_header(); ?>
<div class="portfolio-archive-wrapper">
<header class="archive-header">
<h1 class="archive-title">
<?php
if (is_tax('portfolio_category')) {
single_term_title();
} elseif (is_tax('portfolio_tag')) {
echo 'ํ๊ทธ: ';
single_term_title();
} else {
echo 'ํฌํธํด๋ฆฌ์ค';
}
?>
</h1>
<?php if (is_tax() && term_description()) : ?>
<div class="archive-description">
<?php echo term_description(); ?>
</div>
<?php endif; ?>
</header>
<?php if (have_posts()) : ?>
<div class="portfolio-grid">
<?php while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('portfolio-item'); ?>>
<?php if (has_post_thumbnail()) : ?>
<div class="portfolio-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('medium_large'); ?>
</a>
</div>
<?php endif; ?>
<div class="portfolio-item-content">
<h2 class="portfolio-item-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (has_excerpt()) : ?>
<div class="portfolio-excerpt">
<?php the_excerpt(); ?>
</div>
<?php endif; ?>
<?php
$client = get_post_meta(get_the_ID(), '_portfolio_client', true);
$technologies = get_post_meta(get_the_ID(), '_portfolio_technologies', true);
?>
<div class="portfolio-item-meta">
<?php if ($client) : ?>
<span class="meta-client">
<strong>ํด๋ผ์ด์ธํธ:</strong> <?php echo esc_html($client); ?>
</span>
<?php endif; ?>
<?php if ($technologies) : ?>
<span class="meta-tech">
<strong>๊ธฐ์ :</strong> <?php echo esc_html($technologies); ?>
</span>
<?php endif; ?>
</div>
<a href="<?php the_permalink(); ?>" class="read-more-btn">
์์ธํ ๋ณด๊ธฐ โ
</a>
</div>
</article>
<?php endwhile; ?>
</div>
<!-- ํ์ด์ง๋ค์ด์
-->
<div class="portfolio-pagination">
<?php
the_posts_pagination(array(
'mid_size' => 2,
'prev_text' => 'โ ์ด์ ',
'next_text' => '๋ค์ โ',
));
?>
</div>
<?php else : ?>
<div class="no-posts">
<p>ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค.</p>
</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
๐ก CSS ๊ทธ๋ฆฌ๋๋ก ๋ฐ์ํ ๋ ์ด์์ ๋ง๋ค๊ธฐ
ํฌํธํด๋ฆฌ์ค ๊ทธ๋ฆฌ๋๋ฅผ ๋ฐ์ํ์ผ๋ก ๋ง๋ค๋ ค๋ฉด CSS Grid๋ฅผ ํ์ฉํ๋ฉด ์ข์. style.css์ ์ด๋ฐ ์คํ์ผ์ ์ถ๊ฐํด๋ด:
.portfolio-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 30px;
margin: 40px 0;
}์ด๋ ๊ฒ ํ๋ฉด ํ๋ฉด ํฌ๊ธฐ์ ๋ฐ๋ผ ์๋์ผ๋ก ์ด ๊ฐ์๊ฐ ์กฐ์ ๋ผ!
๐ WP_Query๋ก ์ปค์คํ ํฌ์คํธ ํ์ ์กฐํํ๊ธฐ
WordPress์์ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋ ๊ฐ์ฅ ๊ฐ๋ ฅํ ๋ฐฉ๋ฒ์ WP_Query ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ ๊ฑฐ์ผ. ์ปค์คํ ํฌ์คํธ ํ์ ์ ๋ค์ํ ์กฐ๊ฑด์ผ๋ก ์กฐํํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐
๊ธฐ๋ณธ WP_Query ์ฌ์ฉ๋ฒ
<?php
// ์ต์ ํฌํธํด๋ฆฌ์ค 6๊ฐ ๊ฐ์ ธ์ค๊ธฐ
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 6,
'orderby' => 'date',
'order' => 'DESC'
);
$portfolio_query = new WP_Query($args);
if ($portfolio_query->have_posts()) :
while ($portfolio_query->have_posts()) : $portfolio_query->the_post();
// ํฌ์คํธ ์ถ๋ ฅ
the_title('<h3>', '</h3>');
the_excerpt();
endwhile;
// ์ฟผ๋ฆฌ ๋ฆฌ์
(์ค์!)
wp_reset_postdata();
else :
echo 'ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค.';
endif;
?>
๊ณ ๊ธ ์ฟผ๋ฆฌ ์์
<?php
// ๋ณต์กํ ์กฐ๊ฑด์ ์ฟผ๋ฆฌ
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 12,
// ํ์๋
ธ๋ฏธ ์ฟผ๋ฆฌ
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => 'web-design'
),
array(
'taxonomy' => 'portfolio_tag',
'field' => 'slug',
'terms' => array('wordpress', 'responsive'),
'operator' => 'IN'
)
),
// ๋ฉํ ์ฟผ๋ฆฌ
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_portfolio_client',
'value' => '',
'compare' => '!='
),
array(
'key' => '_portfolio_completion_date',
'value' => date('Y-m-d', strtotime('-1 year')),
'compare' => '>=',
'type' => 'DATE'
)
),
// ์ ๋ ฌ
'orderby' => array(
'meta_value' => 'DESC',
'date' => 'DESC'
),
'meta_key' => '_portfolio_completion_date',
// ํ์ด์ง๋ค์ด์
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
);
$portfolio_query = new WP_Query($args);
?>
๐ฏ WP_Query ์ฃผ์ ํ๋ผ๋ฏธํฐ
ํฌ์คํธ ํ์
๊ด๋ จ:
- post_type: ์กฐํํ ํฌ์คํธ ํ์
- posts_per_page: ํ์ด์ง๋น ํฌ์คํธ ์ (-1์ ์ ์ฒด)
- post_status: ํฌ์คํธ ์ํ (publish, draft, pending ๋ฑ)
์ ๋ ฌ ๊ด๋ จ:
- orderby: ์ ๋ ฌ ๊ธฐ์ค (date, title, rand, meta_value ๋ฑ)
- order: ์ ๋ ฌ ๋ฐฉํฅ (ASC, DESC)
ํ์๋
ธ๋ฏธ ๊ด๋ จ:
- tax_query: ํ์๋
ธ๋ฏธ ์กฐ๊ฑด
- category_name, tag, cat ๋ฑ
๋ฉํ ๋ฐ์ดํฐ ๊ด๋ จ:
- meta_query: ์ปค์คํ
ํ๋ ์กฐ๊ฑด
- meta_key, meta_value: ๋จ์ ๋ฉํ ์กฐํ
๋ ์ง ๊ด๋ จ:
- date_query: ๋ ์ง ๋ฒ์ ์กฐ๊ฑด
- year, monthnum, day ๋ฑ
์ผํธ์ฝ๋๋ก ์ด๋์๋ ์ฌ์ฉํ๊ธฐ
WP_Query๋ฅผ ์ผํธ์ฝ๋๋ก ๋ง๋ค๋ฉด ์๋ํฐ์์ ๊ฐํธํ๊ฒ ์ฌ์ฉํ ์ ์์ด:
<?php
function portfolio_shortcode($atts) {
// ์ผํธ์ฝ๋ ์์ฑ ํ์ฑ
$atts = shortcode_atts(array(
'category' => '',
'count' => 6,
'columns' => 3
), $atts);
// ์ฟผ๋ฆฌ ์ธ์ ์ค์
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => intval($atts['count'])
);
// ์นดํ
๊ณ ๋ฆฌ๊ฐ ์ง์ ๋ ๊ฒฝ์ฐ
if (!empty($atts['category'])) {
$args['tax_query'] = array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => $atts['category']
)
);
}
$portfolio_query = new WP_Query($args);
// ์ถ๋ ฅ ๋ฒํผ ์์
ob_start();
if ($portfolio_query->have_posts()) :
echo '<div class="portfolio-shortcode-grid columns-' . esc_attr($atts['columns']) . '">';
while ($portfolio_query->have_posts()) : $portfolio_query->the_post();
?>
<div class="portfolio-shortcode-item">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('medium'); ?>
</a>
<?php endif; ?>
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php
$client = get_post_meta(get_the_ID(), '_portfolio_client', true);
if ($client) :
echo '<p class="client">' . esc_html($client) . '</p>';
endif;
?>
</div>
<?php
endwhile;
echo '</div>';
wp_reset_postdata();
else :
echo '<p>ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค.</p>';
endif;
// ๋ฒํผ ๋ด์ฉ ๋ฐํ
return ob_get_clean();
}
add_shortcode('portfolio', 'portfolio_shortcode');
// ์ฌ์ฉ ์์:
// [portfolio category="web-design" count="9" columns="3"]
?>
โ ๏ธ wp_reset_postdata() ์์ง ๋ง์ธ์! WP_Query๋ฅผ ์ฌ์ฉํ ํ์๋ ๋ฐ๋์ wp_reset_postdata()๋ฅผ ํธ์ถํด์ผ ํด. ๊ทธ๋์ผ ๊ธ๋ก๋ฒ $post ๋ณ์๊ฐ ์๋๋๋ก ๋ณต์๋ผ์ ๋ค๋ฅธ WordPress ํจ์๋ค์ด ์ ์์ ์ผ๋ก ์๋ํด. ์ด๊ฑฐ ์ ํ๋ฉด ํ์ด์ง์ ๋ค๋ฅธ ๋ถ๋ถ์์ ์ด์ํ ๋ฒ๊ทธ๊ฐ ๋ฐ์ํ ์ ์์ด!
โก REST API๋ก ์ปค์คํ ํฌ์คํธ ํ์ ํ์ฉํ๊ธฐ
WordPress REST API๋ฅผ ์ฌ์ฉํ๋ฉด ์ปค์คํ ํฌ์คํธ ํ์ ๋ฐ์ดํฐ๋ฅผ JSON ํํ๋ก ๊ฐ์ ธ์ฌ ์ ์์ด. ์ด๊ฑธ ํ์ฉํ๋ฉด React, Vue ๊ฐ์ ํ๋ก ํธ์๋ ํ๋ ์์ํฌ์ ์ฐ๋ํ๊ฑฐ๋, ๋ชจ๋ฐ์ผ ์ฑ์์ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ ์ ์์ง! ๐
REST API ๊ธฐ๋ณธ ์ฌ์ฉ
์ปค์คํ ํฌ์คํธ ํ์ ์ ๋ฑ๋กํ ๋ 'show_in_rest' => true๋ก ์ค์ ํ๋ค๋ฉด, ์๋์ผ๋ก REST API ์๋ํฌ์ธํธ๊ฐ ์์ฑ๋ผ:
๊ธฐ๋ณธ ์๋ํฌ์ธํธ:
- ์ ์ฒด ๋ชฉ๋ก: /wp-json/wp/v2/portfolio
- ๋จ์ผ ํญ๋ชฉ: /wp-json/wp/v2/portfolio/{id}
- ์นดํ
๊ณ ๋ฆฌ: /wp-json/wp/v2/portfolio_category
- ํ๊ทธ: /wp-json/wp/v2/portfolio_tag
์ปค์คํ REST API ํ๋ ์ถ๊ฐ
๋ฉํ ๋ฐ์ดํฐ๋ฅผ REST API ์๋ต์ ํฌํจ์ํค๋ ค๋ฉด register_rest_field()๋ฅผ ์ฌ์ฉํด:
<?php
function add_portfolio_meta_to_rest_api() {
// ํด๋ผ์ด์ธํธ ํ๋ ์ถ๊ฐ
register_rest_field('portfolio', 'client', array(
'get_callback' => function($post) {
return get_post_meta($post['id'], '_portfolio_client', true);
},
'update_callback' => function($value, $post) {
return update_post_meta($post->ID, '_portfolio_client', sanitize_text_field($value));
},
'schema' => array(
'description' => 'ํ๋ก์ ํธ ํด๋ผ์ด์ธํธ',
'type' => 'string',
'context' => array('view', 'edit')
)
));
// ํ๋ก์ ํธ URL ํ๋ ์ถ๊ฐ
register_rest_field('portfolio', 'project_url', array(
'get_callback' => function($post) {
return get_post_meta($post['id'], '_portfolio_url', true);
},
'update_callback' => function($value, $post) {
return update_post_meta($post->ID, '_portfolio_url', esc_url_raw($value));
},
'schema' => array(
'description' => 'ํ๋ก์ ํธ URL',
'type' => 'string',
'format' => 'uri',
'context' => array('view', 'edit')
)
));
// ์ฌ์ฉ ๊ธฐ์ ํ๋ ์ถ๊ฐ
register_rest_field('portfolio', 'technologies', array(
'get_callback' => function($post) {
$tech = get_post_meta($post['id'], '_portfolio_technologies', true);
return !empty($tech) ? explode(',', $tech) : array();
},
'update_callback' => function($value, $post) {
if (is_array($value)) {
$value = implode(',', $value);
}
return update_post_meta($post->ID, '_portfolio_technologies', sanitize_text_field($value));
},
'schema' => array(
'description' => '์ฌ์ฉ ๊ธฐ์ ๋ชฉ๋ก',
'type' => 'array',
'items' => array('type' => 'string'),
'context' => array('view', 'edit')
)
));
}
add_action('rest_api_init', 'add_portfolio_meta_to_rest_api');
?>
์ปค์คํ REST API ์๋ํฌ์ธํธ ๋ง๋ค๊ธฐ
์์ ํ ์๋ก์ด ์๋ํฌ์ธํธ๋ฅผ ๋ง๋ค ์๋ ์์ด:
<?php
function register_custom_portfolio_routes() {
// ์ต์ ํฌํธํด๋ฆฌ์ค ๊ฐ์ ธ์ค๊ธฐ
register_rest_route('custom/v1', '/portfolio/latest', array(
'methods' => 'GET',
'callback' => 'get_latest_portfolio',
'permission_callback' => '__return_true'
));
// ์นดํ
๊ณ ๋ฆฌ๋ณ ํฌํธํด๋ฆฌ์ค ๊ฐ์ ธ์ค๊ธฐ
register_rest_route('custom/v1', '/portfolio/category/(?P<slug>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => 'get_portfolio_by_category',
'permission_callback' => '__return_true',
'args' => array(
'slug' => array(
'validate_callback' => function($param) {
return is_string($param);
}
)
)
));
}
add_action('rest_api_init', 'register_custom_portfolio_routes');
function get_latest_portfolio($request) {
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query($args);
$portfolios = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$portfolios[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'excerpt' => get_the_excerpt(),
'link' => get_permalink(),
'thumbnail' => get_the_post_thumbnail_url(get_the_ID(), 'medium'),
'client' => get_post_meta(get_the_ID(), '_portfolio_client', true),
'technologies' => get_post_meta(get_the_ID(), '_portfolio_technologies', true),
'date' => get_the_date('c')
);
}
wp_reset_postdata();
}
return new WP_REST_Response($portfolios, 200);
}
function get_portfolio_by_category($request) {
$slug = $request['slug'];
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => $slug
)
)
);
$query = new WP_Query($args);
$portfolios = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$portfolios[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'excerpt' => get_the_excerpt(),
'link' => get_permalink(),
'thumbnail' => get_the_post_thumbnail_url(get_the_ID(), 'medium')
);
}
wp_reset_postdata();
}
if (empty($portfolios)) {
return new WP_Error('no_portfolios', 'ํด๋น ์นดํ
๊ณ ๋ฆฌ์ ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค.', array('status' => 404));
}
return new WP_REST_Response($portfolios, 200);
}
?>
๐ก JavaScript๋ก REST API ์ฌ์ฉํ๊ธฐ
ํ๋ก ํธ์๋์์ Fetch API๋ Axios๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ด:
fetch('/wp-json/wp/v2/portfolio?per_page=6')
.then(response => response.json())
.then(data => {
console.log(data);
// ๋ฐ์ดํฐ ์ฒ๋ฆฌ
});์ด๋ ๊ฒ ํ๋ฉด ํ์ด์ง ์๋ก๊ณ ์นจ ์์ด ๋์ ์ผ๋ก ์ฝํ ์ธ ๋ฅผ ๋ก๋ํ ์ ์์ด!
๐จ ์ค์ ํ๋ก์ ํธ: ์์ ํ ํฌํธํด๋ฆฌ์ค ์์คํ ๊ตฌ์ถ
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ ์ข ํฉํด์ ์ค์ ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ ํฌํธํด๋ฆฌ์ค ์์คํ ์ ๋ง๋ค์ด๋ณด์! ์ด ์์ ๋ ํ๋ฌ๊ทธ์ธ ํํ๋ก ๋ง๋ค์ด์ ์ด๋ค ํ ๋ง์์๋ ์ฌ์ฉํ ์ ์๊ฒ ํ ๊ฑฐ์ผ. ๐
ํ๋ฌ๊ทธ์ธ ๋ฉ์ธ ํ์ผ ๊ตฌ์กฐ
<?php
/*
Plugin Name: Advanced Portfolio Manager
Plugin URI: https://www.jaenung.net/portfolio-manager
Description: ๊ฐ๋ ฅํ ํฌํธํด๋ฆฌ์ค ๊ด๋ฆฌ ์์คํ
Version: 1.0.0
Author: Your Name
Author URI: https://www.jaenung.net
License: GPL2
Text Domain: advanced-portfolio
*/
if (!defined('ABSPATH')) exit;
// ํ๋ฌ๊ทธ์ธ ์์ ์ ์
define('APM_VERSION', '1.0.0');
define('APM_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('APM_PLUGIN_URL', plugin_dir_url(__FILE__));
// ํด๋์ค ์คํ ๋ก๋
spl_autoload_register(function($class) {
$prefix = 'APM_';
$base_dir = APM_PLUGIN_DIR . 'includes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('_', '-', strtolower($relative_class)) . '.php';
if (file_exists($file)) {
require $file;
}
});
// ๋ฉ์ธ ํ๋ฌ๊ทธ์ธ ํด๋์ค
class Advanced_Portfolio_Manager {
private static $instance = null;
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
$this->init_hooks();
}
private function init_hooks() {
// ํฌ์คํธ ํ์
๋ฑ๋ก
add_action('init', array($this, 'register_post_type'));
add_action('init', array($this, 'register_taxonomies'));
// ๋ฉํ๋ฐ์ค
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
add_action('save_post_portfolio', array($this, 'save_meta_boxes'));
// ์คํ์ผ & ์คํฌ๋ฆฝํธ
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
// REST API
add_action('rest_api_init', array($this, 'register_rest_fields'));
// ์ผํธ์ฝ๋
add_shortcode('portfolio', array($this, 'portfolio_shortcode'));
add_shortcode('portfolio_filter', array($this, 'portfolio_filter_shortcode'));
// ๊ด๋ฆฌ์ ์ค์
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_init', array($this, 'register_settings'));
}
public function register_post_type() {
$labels = array(
'name' => 'ํฌํธํด๋ฆฌ์ค',
'singular_name' => 'ํฌํธํด๋ฆฌ์ค',
'add_new' => '์ ํ๋ก์ ํธ ์ถ๊ฐ',
'add_new_item' => '์ ํฌํธํด๋ฆฌ์ค ์ถ๊ฐ',
'edit_item' => 'ํฌํธํด๋ฆฌ์ค ์์ ',
'new_item' => '์ ํฌํธํด๋ฆฌ์ค',
'view_item' => 'ํฌํธํด๋ฆฌ์ค ๋ณด๊ธฐ',
'search_items' => 'ํฌํธํด๋ฆฌ์ค ๊ฒ์',
'not_found' => 'ํฌํธํด๋ฆฌ์ค๊ฐ ์์ต๋๋ค',
'menu_name' => 'ํฌํธํด๋ฆฌ์ค'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'menu_icon' => 'dashicons-portfolio',
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
'rewrite' => array('slug' => 'portfolio'),
'capability_type' => 'post'
);
register_post_type('portfolio', $args);
}
public function register_taxonomies() {
// ์นดํ
๊ณ ๋ฆฌ
register_taxonomy('portfolio_category', 'portfolio', array(
'labels' => array(
'name' => '์นดํ
๊ณ ๋ฆฌ',
'singular_name' => '์นดํ
๊ณ ๋ฆฌ'
),
'hierarchical' => true,
'show_in_rest' => true,
'rewrite' => array('slug' => 'portfolio-category')
));
// ํ๊ทธ
register_taxonomy('portfolio_tag', 'portfolio', array(
'labels' => array(
'name' => 'ํ๊ทธ',
'singular_name' => 'ํ๊ทธ'
),
'hierarchical' => false,
'show_in_rest' => true,
'rewrite' => array('slug' => 'portfolio-tag')
));
}
public function add_meta_boxes() {
add_meta_box(
'portfolio_details',
'ํ๋ก์ ํธ ์์ธ ์ ๋ณด',
array($this, 'render_meta_box'),
'portfolio',
'normal',
'high'
);
}
public function render_meta_box($post) {
wp_nonce_field('portfolio_meta_box', 'portfolio_meta_box_nonce');
$fields = array(
'client' => 'ํด๋ผ์ด์ธํธ',
'duration' => 'ํ๋ก์ ํธ ๊ธฐ๊ฐ',
'technologies' => '์ฌ์ฉ ๊ธฐ์ ',
'url' => 'ํ๋ก์ ํธ URL',
'completion_date' => '์๋ฃ์ผ'
);
echo '<div class="apm-meta-box">';
foreach ($fields as $key => $label) {
$value = get_post_meta($post->ID, '_portfolio_' . $key, true);
$type = ($key === 'url') ? 'url' : (($key === 'completion_date') ? 'date' : 'text');
echo '<p>';
echo '<label for="portfolio_' . $key . '"><strong>' . $label . ':</strong></label><br>';
echo '<input type="' . $type . '" id="portfolio_' . $key . '" name="portfolio_' . $key . '" ';
echo 'value="' . esc_attr($value) . '" style="width: 100%;" />';
echo '</p>';
}
echo '</div>';
}
public function save_meta_boxes($post_id) {
if (!isset($_POST['portfolio_meta_box_nonce'])) return;
if (!wp_verify_nonce($_POST['portfolio_meta_box_nonce'], 'portfolio_meta_box')) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!current_user_can('edit_post', $post_id)) return;
$fields = array('client', 'duration', 'technologies', 'url', 'completion_date');
foreach ($fields as $field) {
if (isset($_POST['portfolio_' . $field])) {
$value = $_POST['portfolio_' . $field];
if ($field === 'url') {
$value = esc_url_raw($value);
} else {
$value = sanitize_text_field($value);
}
update_post_meta($post_id, '_portfolio_' . $field, $value);
}
}
}
public function enqueue_scripts() {
if (is_post_type_archive('portfolio') || is_singular('portfolio') || is_tax(array('portfolio_category', 'portfolio_tag'))) {
wp_enqueue_style('apm-style', APM_PLUGIN_URL . 'assets/css/style.css', array(), APM_VERSION);
wp_enqueue_script('apm-script', APM_PLUGIN_URL . 'assets/js/script.js', array('jquery'), APM_VERSION, true);
wp_localize_script('apm-script', 'apmData', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('apm_nonce')
));
}
}
public function admin_enqueue_scripts($hook) {
if ('post.php' === $hook || 'post-new.php' === $hook) {
global $post_type;
if ('portfolio' === $post_type) {
wp_enqueue_style('apm-admin-style', APM_PLUGIN_URL . 'assets/css/admin.css', array(), APM_VERSION);
}
}
}
public function register_rest_fields() {
$meta_fields = array('client', 'duration', 'technologies', 'url', 'completion_date');
foreach ($meta_fields as $field) {
register_rest_field('portfolio', $field, array(
'get_callback' => function($post) use ($field) {
return get_post_meta($post['id'], '_portfolio_' . $field, true);
},
'schema' => array(
'description' => ucfirst($field),
'type' => 'string'
)
));
}
}
public function portfolio_shortcode($atts) {
$atts = shortcode_atts(array(
'count' => 6,
'category' => '',
'columns' => 3,
'orderby' => 'date',
'order' => 'DESC'
), $atts);
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => intval($atts['count']),
'orderby' => $atts['orderby'],
'order' => $atts['order']
);
if (!empty($atts['category'])) {
$args['tax_query'] = array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => $atts['category']
)
);
}
$query = new WP_Query($args);
ob_start();
if ($query->have_posts()) {
echo '<div class="apm-portfolio-grid columns-' . esc_attr($atts['columns']) . '">';
while ($query->have_posts()) {
$query->the_post();
include APM_PLUGIN_DIR . 'templates/portfolio-item.php';
}
echo '</div>';
wp_reset_postdata();
}
return ob_get_clean();
}
public function portfolio_filter_shortcode($atts) {
$terms = get_terms(array(
'taxonomy' => 'portfolio_category',
'hide_empty' => true
));
if (empty($terms) || is_wp_error($terms)) {
return '';
}
ob_start();
echo '<div class="apm-portfolio-filter">';
echo '<button class="filter-btn active" data-filter="*">์ ์ฒด</button>';
foreach ($terms as $term) {
echo '<button class="filter-btn" data-filter="' . esc_attr($term->slug) . '">';
echo esc_html($term->name);
echo '</button>';
}
echo '</div>';
return ob_get_clean();
}
public function add_admin_menu() {
add_submenu_page(
'edit.php?post_type=portfolio',
'์ค์ ',
'์ค์ ',
'manage_options',
'portfolio-settings',
array($this, 'settings_page')
);
}
public function register_settings() {
register_setting('apm_settings', 'apm_options');
add_settings_section(
'apm_main_section',
'ํฌํธํด๋ฆฌ์ค ์ค์ ',
null,
'portfolio-settings'
);
add_settings_field(
'apm_items_per_page',
'ํ์ด์ง๋น ํญ๋ชฉ ์',
array($this, 'items_per_page_callback'),
'portfolio-settings',
'apm_main_section'
);
}
public function items_per_page_callback() {
$options = get_option('apm_options');
$value = isset($options['items_per_page']) ? $options['items_per_page'] : 12;
echo '<input type="number" name="apm_options[items_per_page]" value="' . esc_attr($value) . '" min="1" />';
}
public function settings_page() {
?>
<div class="wrap">
<h1>ํฌํธํด๋ฆฌ์ค ์ค์ </h1>
<form method="post" action="options.php">
<?php
settings_fields('apm_settings');
do_settings_sections('portfolio-settings');
submit_button();
?>
</form>
</div>
<?php
}
}
// ํ๋ฌ๊ทธ์ธ ํ์ฑํ
function activate_advanced_portfolio_manager() {
Advanced_Portfolio_Manager::get_instance();
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'activate_advanced_portfolio_manager');
// ํ๋ฌ๊ทธ์ธ ๋นํ์ฑํ
function deactivate_advanced_portfolio_manager() {
flush_rewrite_rules();
}
register_deactivation_hook(__FILE__, 'deactivate_advanced_portfolio_manager');
// ํ๋ฌ๊ทธ์ธ ์ด๊ธฐํ
function init_advanced_portfolio_manager() {
Advanced_Portfolio_Manager::get_instance();
}
add_action('plugins_loaded', 'init_advanced_portfolio_manager');
?>
๐๏ธ ํ๋ฌ๊ทธ์ธ ํด๋ ๊ตฌ์กฐ
advanced-portfolio-manager/
โโโ advanced-portfolio-manager.php (๋ฉ์ธ ํ์ผ)
โโโ assets/
โ โโโ css/
โ โ โโโ style.css
โ โ โโโ admin.css
โ โโโ js/
โ โโโ script.js
โโโ includes/
โ โโโ class-post-type.php
โ โโโ class-taxonomy.php
โ โโโ class-meta-box.php
โโโ templates/
โ โโโ portfolio-item.php
โ โโโ single-portfolio.php
โ โโโ archive-portfolio.php
โโโ readme.txt
๐ง ์ฑ๋ฅ ์ต์ ํ์ ๋ฒ ์คํธ ํ๋ํฐ์ค
WordPress ๊ฐ๋ฐ์์ ์ฑ๋ฅ์ ๋งค์ฐ ์ค์ํด. ํนํ ์ปค์คํ ํฌ์คํธ ํ์ ์ ๋ง์ด ์ฌ์ฉํ๋ ์ฌ์ดํธ๋ผ๋ฉด ๋์ฑ ๊ทธ๋ ์ง. ์ฑ๋ฅ ์ต์ ํ ํ์ ์์๋ณด์! โก
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฟผ๋ฆฌ ์ต์ ํ
1. ๋ถํ์ํ ์ฟผ๋ฆฌ ์ค์ด๊ธฐ
- update_post_meta() ๋์ ์กฐ๊ฑด๋ถ๋ก ์ฌ์ฉ
- ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ฌ ๋ฒ ์กฐํํ์ง ์๊ธฐ
- ํธ๋์ง์ธํธ(Transient) API ํ์ฉํด์ ์บ์ฑ
2. ํจ์จ์ ์ธ WP_Query ์ฌ์ฉ
- 'fields' ํ๋ผ๋ฏธํฐ๋ก ํ์ํ ํ๋๋ง ๊ฐ์ ธ์ค๊ธฐ
- 'no_found_rows' => true๋ก ์ด ๊ฐ์ ๊ณ์ฐ ์๋ต
- 'update_post_meta_cache', 'update_post_term_cache' ์กฐ์
3. ์ธ๋ฑ์ค ํ์ฉ
- ์์ฃผ ์กฐํํ๋ ๋ฉํ ํค์ ์ธ๋ฑ์ค ์ถ๊ฐ
- ์ปค์คํ
ํ
์ด๋ธ ์ฌ์ฉ ์ ์ ์ ํ ์ธ๋ฑ์ค ์ค์
์บ์ฑ ์ ๋ต
<?php
// ํธ๋์ง์ธํธ๋ฅผ ์ฌ์ฉํ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ ์บ์ฑ
function get_cached_portfolio_items($category = '', $count = 10) {
// ์บ์ ํค ์์ฑ
$cache_key = 'portfolio_' . md5($category . $count);
// ์บ์๋ ๋ฐ์ดํฐ ํ์ธ
$cached_data = get_transient($cache_key);
if (false !== $cached_data) {
return $cached_data;
}
// ์บ์๊ฐ ์์ผ๋ฉด ์ฟผ๋ฆฌ ์คํ
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $count,
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false
);
if (!empty($category)) {
$args['tax_query'] = array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => $category
)
);
}
$query = new WP_Query($args);
$items = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$items[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'permalink' => get_permalink(),
'thumbnail' => get_the_post_thumbnail_url(get_the_ID(), 'medium')
);
}
wp_reset_postdata();
}
// 1์๊ฐ ๋์ ์บ์ ์ ์ฅ
set_transient($cache_key, $items, HOUR_IN_SECONDS);
return $items;
}
// ํฌํธํด๋ฆฌ์ค ์ ์ฅ/์์ ์ ์บ์ ์ญ์
function clear_portfolio_cache($post_id) {
if (get_post_type($post_id) !== 'portfolio') {
return;
}
// ๊ด๋ จ ์บ์ ๋ชจ๋ ์ญ์
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_portfolio_%'");
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_portfolio_%'");
}
add_action('save_post_portfolio', 'clear_portfolio_cache');
add_action('delete_post', 'clear_portfolio_cache');
?>
์ด๋ฏธ์ง ์ต์ ํ
<?php
// ์ปค์คํ
์ด๋ฏธ์ง ์ฌ์ด์ฆ ๋ฑ๋ก
function register_portfolio_image_sizes() {
add_image_size('portfolio-thumbnail', 400, 300, true);
add_image_size('portfolio-medium', 800, 600, true);
add_image_size('portfolio-large', 1200, 900, true);
}
add_action('after_setup_theme', 'register_portfolio_image_sizes');
// ์ด๋ฏธ์ง ์ฌ์ด์ฆ ์ ํ ์ต์
์ ์ถ๊ฐ
function add_portfolio_image_sizes_to_media($sizes) {
return array_merge($sizes, array(
'portfolio-thumbnail' => 'ํฌํธํด๋ฆฌ์ค ์ธ๋ค์ผ',
'portfolio-medium' => 'ํฌํธํด๋ฆฌ์ค ์ค๊ฐ',
'portfolio-large' => 'ํฌํธํด๋ฆฌ์ค ํฐ ์ด๋ฏธ์ง'
));
}
add_filter('image_size_names_choose', 'add_portfolio_image_sizes_to_media');
// Lazy Loading ์ ์ฉ
function add_lazy_loading_to_portfolio_images($attr, $attachment, $size) {
if (is_singular('portfolio') || is_post_type_archive('portfolio')) {
$attr['loading'] = 'lazy';
}
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'add_lazy_loading_to_portfolio_images', 10, 3);
?>
โ ๏ธ ๊ณผ๋ํ ์ต์ ํ ์ฃผ์ ์ต์ ํ๋ ์ข์ง๋ง, ๋๋ฌด ๋ณต์กํ๊ฒ ๋ง๋ค๋ฉด ์คํ๋ ค ์ ์ง๋ณด์๊ฐ ์ด๋ ค์์ ธ. ์ค์ ๋ก ์ฑ๋ฅ ๋ฌธ์ ๊ฐ ์์ ๋๋ง ์ต์ ํํ๊ณ , ํญ์ ์ธก์ ๊ฐ๋ฅํ ๊ฐ์ ์ ๋ชฉํ๋ก ํด์ผ ํด. Query Monitor ๊ฐ์ ํ๋ฌ๊ทธ์ธ์ผ๋ก ์ค์ ๋ณ๋ชฉ ์ง์ ์ ์ฐพ์์ ์ง์ค์ ์ผ๋ก ๊ฐ์ ํ๋ ๊ฒ ํจ์จ์ ์ด์ผ!
๋ณด์ ๋ฒ ์คํธ ํ๋ํฐ์ค
๐ WordPress ๋ณด์ ์ฒดํฌ๋ฆฌ์คํธ
1. ์
๋ ฅ ๊ฒ์ฆ (Input Validation)
- ๋ชจ๋ ์ฌ์ฉ์ ์
๋ ฅ์ ๊ฒ์ฆํ๊ณ ์ ์
- sanitize_text_field(), sanitize_email(), esc_url_raw() ๋ฑ ์ฌ์ฉ
2. ์ถ๋ ฅ ์ด์ค์ผ์ดํ (Output Escaping)
- esc_html(), esc_attr(), esc_url() ๋ฑ์ผ๋ก XSS ๋ฐฉ์ง
- wp_kses()๋ก ํ์ฉ๋ HTML๋ง ์ถ๋ ฅ
3. Nonce ๊ฒ์ฆ
- ๋ชจ๋ ํผ๊ณผ AJAX ์์ฒญ์ nonce ์ฌ์ฉ
- wp_create_nonce(), wp_verify_nonce() ํ์ฉ
4. ๊ถํ ํ์ธ
- current_user_can()์ผ๋ก ๊ถํ ์ฒดํฌ
- ๋ฏผ๊ฐํ ์์
์ ๊ด๋ฆฌ์๋ง ๊ฐ๋ฅํ๋๋ก
5. SQL ์ธ์ ์
๋ฐฉ์ง
- $wpdb->prepare() ์ฌ์ฉ
- ์ง์ SQL ์ฟผ๋ฆฌ ์์ฑ ์ ํนํ ์ฃผ์
6. ํ์ผ ์
๋ก๋ ๋ณด์
- ํ์ฉ๋ ํ์ผ ํ์
๋ง ์
๋ก๋
- ํ์ผ๋ช
๊ฒ์ฆ ๋ฐ ์ ์
- ์
๋ก๋ ๋๋ ํ ๋ฆฌ ๊ถํ ์ค์
๐ ์ค๋ฌด์์ ์์ฃผ ์ฌ์ฉํ๋ ๊ณ ๊ธ ๊ธฐ๋ฅ
์ด์ ์ค๋ฌด์์ ์ ๋ง ์ ์ฉํ ๊ณ ๊ธ ๊ธฐ๋ฅ๋ค์ ์์๋ณด์. ์ด๋ฐ ๊ธฐ๋ฅ๋ค์ ์๊ณ ์์ผ๋ฉด ํด๋ผ์ด์ธํธ ์๊ตฌ์ฌํญ์ ํจ์ฌ ์ฝ๊ฒ ๊ตฌํํ ์ ์์ด! ๐ช
AJAX๋ฅผ ํ์ฉํ ํํฐ๋ง ์์คํ
ํ์ด์ง ์๋ก๊ณ ์นจ ์์ด ํฌํธํด๋ฆฌ์ค๋ฅผ ํํฐ๋งํ๋ ๊ธฐ๋ฅ์ ๋ง๋ค์ด๋ณด์:
<?php
// AJAX ํธ๋ค๋ฌ ๋ฑ๋ก
function register_portfolio_ajax_handlers() {
add_action('wp_ajax_filter_portfolio', 'ajax_filter_portfolio');
add_action('wp_ajax_nopriv_filter_portfolio', 'ajax_filter_portfolio');
}
add_action('init', 'register_portfolio_ajax_handlers');
// AJAX ์ฝ๋ฐฑ ํจ์
function ajax_filter_portfolio() {
check_ajax_referer('portfolio_filter_nonce', 'nonce');
$category = isset($_POST['category']) ? sanitize_text_field($_POST['category']) : '';
$paged = isset($_POST['page']) ? intval($_POST['page']) : 1;
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 9,
'paged' => $paged
);
if (!empty($category) && $category !== 'all') {
$args['tax_query'] = array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => $category
)
);
}
$query = new WP_Query($args);
$response = array(
'success' => false,
'html' => '',
'max_pages' => $query->max_num_pages
);
if ($query->have_posts()) {
ob_start();
while ($query->have_posts()) {
$query->the_post();
?>
<div class="portfolio-item" data-category="<?php echo esc_attr($category); ?>">
<?php if (has_post_thumbnail()) : ?>
<div class="portfolio-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('portfolio-medium'); ?>
</a>
</div>
<?php endif; ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
$client = get_post_meta(get_the_ID(), '_portfolio_client', true);
if ($client) :
echo '<p class="client">' . esc_html($client) . '</p>';
endif;
?>
</div>
<?php
}
$response['html'] = ob_get_clean();
$response['success'] = true;
wp_reset_postdata();
}
wp_send_json($response);
}
// JavaScript ํ์ผ์ ๋ฐ์ดํฐ ์ ๋ฌ
function enqueue_portfolio_filter_script() {
wp_enqueue_script('portfolio-filter', get_template_directory_uri() . '/js/portfolio-filter.js', array('jquery'), '1.0', true);
wp_localize_script('portfolio-filter', 'portfolioFilter', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('portfolio_filter_nonce')
));
}
add_action('wp_enqueue_scripts', 'enqueue_portfolio_filter_script');
?>
JavaScript ํ์ผ (portfolio-filter.js):
jQuery(document).ready(function($) {
let currentPage = 1;
let currentCategory = 'all';
let isLoading = false;
// ํํฐ ๋ฒํผ ํด๋ฆญ
$('.portfolio-filter-btn').on('click', function(e) {
e.preventDefault();
if (isLoading) return;
const category = $(this).data('category');
// ํ์ฑ ๋ฒํผ ๋ณ๊ฒฝ
$('.portfolio-filter-btn').removeClass('active');
$(this).addClass('active');
// ์นดํ
๊ณ ๋ฆฌ ๋ณ๊ฒฝ ์ ํ์ด์ง ๋ฆฌ์
if (category !== currentCategory) {
currentCategory = category;
currentPage = 1;
loadPortfolio(true);
}
});
// ๋๋ณด๊ธฐ ๋ฒํผ ํด๋ฆญ
$('.load-more-btn').on('click', function(e) {
e.preventDefault();
if (isLoading) return;
currentPage++;
loadPortfolio(false);
});
// ํฌํธํด๋ฆฌ์ค ๋ก๋ ํจ์
function loadPortfolio(replace = true) {
isLoading = true;
// ๋ก๋ฉ ํ์
$('.portfolio-grid').addClass('loading');
$.ajax({
url: portfolioFilter.ajaxUrl,
type: 'POST',
data: {
action: 'filter_portfolio',
nonce: portfolioFilter.nonce,
category: currentCategory,
page: currentPage
},
success: function(response) {
if (response.success) {
if (replace) {
// ๊ธฐ์กด ํญ๋ชฉ ๊ต์ฒด
$('.portfolio-grid').html(response.html);
} else {
// ๊ธฐ์กด ํญ๋ชฉ์ ์ถ๊ฐ
$('.portfolio-grid').append(response.html);
}
// ๋๋ณด๊ธฐ ๋ฒํผ ํ์/์จ๊น
if (currentPage >= response.max_pages) {
$('.load-more-btn').hide();
} else {
$('.load-more-btn').show();
}
// ์ ๋๋ฉ์ด์
ํจ๊ณผ
$('.portfolio-item').each(function(index) {
$(this).css({
'opacity': '0',
'transform': 'translateY(20px)'
}).delay(index * 100).animate({
'opacity': '1'
}, 500).css('transform', 'translateY(0)');
});
}
},
error: function(xhr, status, error) {
console.error('AJAX Error:', error);
alert('ํฌํธํด๋ฆฌ์ค๋ฅผ ๋ถ๋ฌ์ค๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.');
},
complete: function() {
isLoading = false;
$('.portfolio-grid').removeClass('loading');
}
});
}
// ๋ฌดํ ์คํฌ๋กค (์ ํ์ฌํญ)
let scrollTimeout;
$(window).on('scroll', function() {
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(function() {
if (isLoading) return;
const scrollTop = $(window).scrollTop();
const windowHeight = $(window).height();
const documentHeight = $(document).height();
// ํ์ด์ง ํ๋จ 200px ์ ์ ๋๋ฌํ๋ฉด ๋ก๋
if (scrollTop + windowHeight > documentHeight - 200) {
if (currentPage < $('.portfolio-grid').data('max-pages')) {
currentPage++;
loadPortfolio(false);
}
}
}, 250);
});
});
์ปค์คํ ๊ด๋ฆฌ์ ์ปฌ๋ผ ์ถ๊ฐ
๊ด๋ฆฌ์ ๋ชฉ๋ก ํ์ด์ง์ ์ ์ฉํ ์ ๋ณด๋ฅผ ํ์ํ์:
<?php
// ์ปค์คํ
์ปฌ๋ผ ์ถ๊ฐ
function add_portfolio_admin_columns($columns) {
$new_columns = array();
foreach ($columns as $key => $value) {
$new_columns[$key] = $value;
// ์ ๋ชฉ ๋ค์์ ์ธ๋ค์ผ ์ถ๊ฐ
if ($key === 'title') {
$new_columns['thumbnail'] = '์ธ๋ค์ผ';
$new_columns['client'] = 'ํด๋ผ์ด์ธํธ';
$new_columns['technologies'] = '์ฌ์ฉ ๊ธฐ์ ';
$new_columns['completion_date'] = '์๋ฃ์ผ';
}
}
return $new_columns;
}
add_filter('manage_portfolio_posts_columns', 'add_portfolio_admin_columns');
// ์ปฌ๋ผ ๋ด์ฉ ์ถ๋ ฅ
function display_portfolio_admin_columns($column, $post_id) {
switch ($column) {
case 'thumbnail':
if (has_post_thumbnail($post_id)) {
echo get_the_post_thumbnail($post_id, array(60, 60));
} else {
echo 'โ';
}
break;
case 'client':
$client = get_post_meta($post_id, '_portfolio_client', true);
echo $client ? esc_html($client) : 'โ';
break;
case 'technologies':
$tech = get_post_meta($post_id, '_portfolio_technologies', true);
if ($tech) {
$tech_array = explode(',', $tech);
echo '<div class="tech-badges">';
foreach ($tech_array as $t) {
echo '<span class="tech-badge">' . esc_html(trim($t)) . '</span> ';
}
echo '</div>';
} else {
echo 'โ';
}
break;
case 'completion_date':
$date = get_post_meta($post_id, '_portfolio_completion_date', true);
if ($date) {
echo date_i18n('Y๋
m์ d์ผ', strtotime($date));
} else {
echo 'โ';
}
break;
}
}
add_action('manage_portfolio_posts_custom_column', 'display_portfolio_admin_columns', 10, 2);
// ์ปฌ๋ผ ์ ๋ ฌ ๊ฐ๋ฅํ๊ฒ ๋ง๋ค๊ธฐ
function make_portfolio_columns_sortable($columns) {
$columns['client'] = 'client';
$columns['completion_date'] = 'completion_date';
return $columns;
}
add_filter('manage_edit-portfolio_sortable_columns', 'make_portfolio_columns_sortable');
// ์ ๋ ฌ ์ฟผ๋ฆฌ ์์
function portfolio_column_orderby($query) {
if (!is_admin() || !$query->is_main_query()) {
return;
}
$orderby = $query->get('orderby');
if ('client' === $orderby) {
$query->set('meta_key', '_portfolio_client');
$query->set('orderby', 'meta_value');
}
if ('completion_date' === $orderby) {
$query->set('meta_key', '_portfolio_completion_date');
$query->set('orderby', 'meta_value');
$query->set('meta_type', 'DATE');
}
}
add_action('pre_get_posts', 'portfolio_column_orderby');
// ๊ด๋ฆฌ์ CSS
function portfolio_admin_column_styles() {
echo '<style>
.column-thumbnail { width: 80px; }
.column-client { width: 150px; }
.column-technologies { width: 200px; }
.column-completion_date { width: 120px; }
.tech-badge {
display: inline-block;
padding: 2px 8px;
background: #e3f2fd;
color: #1976d2;
border-radius: 3px;
font-size: 11px;
margin: 2px;
}
</style>';
}
add_action('admin_head', 'portfolio_admin_column_styles');
?>
๋น ๋ฅธ ํธ์ง(Quick Edit) ์ง์
<?php
// Quick Edit์ ์ปค์คํ
ํ๋ ์ถ๊ฐ
function portfolio_quick_edit_custom_box($column_name, $post_type) {
if ($post_type !== 'portfolio') return;
if ($column_name === 'client') {
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label>
<span class="title">ํด๋ผ์ด์ธํธ</span>
<span class="input-text-wrap">
<input type="text" name="portfolio_client" value="" />
</span>
</label>
<label>
<span class="title">์๋ฃ์ผ</span>
<span class="input-text-wrap">
<input type="date" name="portfolio_completion_date" value="" />
</span>
</label>
</div>
</fieldset>
<?php
}
}
add_action('quick_edit_custom_box', 'portfolio_quick_edit_custom_box', 10, 2);
// Quick Edit ๋ฐ์ดํฐ ์ ์ฅ
function save_portfolio_quick_edit($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!current_user_can('edit_post', $post_id)) return;
if (get_post_type($post_id) !== 'portfolio') return;
if (isset($_POST['portfolio_client'])) {
update_post_meta($post_id, '_portfolio_client', sanitize_text_field($_POST['portfolio_client']));
}
if (isset($_POST['portfolio_completion_date'])) {
update_post_meta($post_id, '_portfolio_completion_date', sanitize_text_field($_POST['portfolio_completion_date']));
}
}
add_action('save_post', 'save_portfolio_quick_edit');
// Quick Edit์ ํ์ฌ ๊ฐ ํ์ํ๊ธฐ ์ํ JavaScript
function portfolio_quick_edit_script() {
global $current_screen;
if ($current_screen->post_type !== 'portfolio') return;
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
const $wp_inline_edit = inlineEditPost.edit;
inlineEditPost.edit = function(id) {
$wp_inline_edit.apply(this, arguments);
const post_id = 0;
if (typeof(id) === 'object') {
post_id = parseInt(this.getId(id));
}
if (post_id > 0) {
const $row = $('#post-' + post_id);
const client = $row.find('.column-client').text().trim();
const date = $row.find('.column-completion_date').data('date');
$('input[name="portfolio_client"]').val(client !== 'โ' ? client : '');
$('input[name="portfolio_completion_date"]').val(date || '');
}
};
});
</script>
<?php
}
add_action('admin_footer', 'portfolio_quick_edit_script');
?>
๐ก ์ฌ๋ฅ๋ท์์ ํ์ฉํ๊ธฐ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์ด๋ฐ ์ปค์คํ ํฌ์คํธ ํ์ ๊ธฐ๋ฅ์ ํ์ฉํ๋ฉด, ๋ค์ํ ์ฌ๋ฅ ์๋น์ค๋ฅผ ์ฒด๊ณ์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์์ด. ์๋ฅผ ๋ค์ด '๋์์ธ', '๊ฐ๋ฐ', '๋ง์ผํ ' ๊ฐ์ ์นดํ ๊ณ ๋ฆฌ๋ก ๋ถ๋ฅํ๊ณ , ๊ฐ ์๋น์ค์ ๊ฐ๊ฒฉ, ์์ ์๊ฐ, ํฌํธํด๋ฆฌ์ค ๋ฑ์ ์ปค์คํ ํ๋๋ก ๊ด๋ฆฌํ๋ฉด ์ฌ์ฉ์๋ค์ด ์ํ๋ ์๋น์ค๋ฅผ ์ฝ๊ฒ ์ฐพ์ ์ ์๊ฒ ์ง? ๐
๐ ํ์ต ๋ฆฌ์์ค์ ๋ค์ ๋จ๊ณ
์ฌ๊ธฐ๊น์ง WordPress ํ๋ฌ๊ทธ์ธ, ํ ๋ง ๊ฐ๋ฐ, ๊ทธ๋ฆฌ๊ณ ์ปค์คํ ํฌ์คํธ ํ์ ํ์ฉ๋ฒ์ ๊น์ด ์๊ฒ ๋ค๋ค๋ดค์ด. ํ์ง๋ง WordPress ๊ฐ๋ฐ์ ์ธ๊ณ๋ ์ ๋ง ๋๊ณ ๊น์ด. ๊ณ์ ํ์ตํ๊ณ ์ฑ์ฅํ๊ธฐ ์ํ ๋ฆฌ์์ค๋ค์ ์๊ฐํ ๊ฒ! ๐
๊ณต์ ๋ฌธ์์ ๋ฆฌ์์ค
๐ ํ์ ํ์ต ์๋ฃ
1. WordPress Codex & Developer Resources
- developer.wordpress.org - ๊ณต์ ๊ฐ๋ฐ์ ๋ฌธ์
- codex.wordpress.org - WordPress Codex (๋ ๊ฑฐ์ ๋ฌธ์)
2. WordPress Plugin Handbook
- ํ๋ฌ๊ทธ์ธ ๊ฐ๋ฐ ๊ฐ์ด๋
- ๋ฒ ์คํธ ํ๋ํฐ์ค์ ๋ณด์ ๊ฐ์ด๋
3. WordPress Theme Handbook
- ํ
๋ง ๊ฐ๋ฐ ์๋ฒฝ ๊ฐ์ด๋
- ํ
ํ๋ฆฟ ๊ณ์ธต ๊ตฌ์กฐ ์์ธ ์ค๋ช
4. WordPress REST API Handbook
- REST API ํ์ฉ๋ฒ
- ์ปค์คํ
์๋ํฌ์ธํธ ์์ฑ
5. WordPress Coding Standards
- PHP, HTML, CSS, JavaScript ์ฝ๋ฉ ํ์ค
- ์ฝ๋ ํ์ง ์ ์ง ๊ฐ์ด๋
์ ์ฉํ ๋๊ตฌ๋ค
| ๋๊ตฌ | ์ฉ๋ | ์ถ์ฒ ์ด์ |
|---|---|---|
| Query Monitor | ๋๋ฒ๊น & ์ฑ๋ฅ ๋ถ์ | ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฟผ๋ฆฌ, ํ , HTTP ์์ฒญ ๋ฑ ๋ชจ๋ํฐ๋ง |
| Debug Bar | ๋๋ฒ๊น | WordPress ๋ด๋ถ ๋์ ํ์ธ |
| WP-CLI | ์ปค๋งจ๋๋ผ์ธ ๋๊ตฌ | ๋น ๋ฅธ ๊ฐ๋ฐ ๋ฐ ๋ฐฐํฌ ์๋ํ |
| Advanced Custom Fields | ์ปค์คํ ํ๋ ๊ด๋ฆฌ | GUI๋ก ์ฝ๊ฒ ํ๋ ์์ฑ |
| GeneratePress | ์คํํฐ ํ ๋ง | ๊ฐ๋ณ๊ณ ํ์ฅ ๊ฐ๋ฅํ ๊ธฐ๋ณธ ํ ๋ง |
| Underscores (_s) | ์คํํฐ ํ ๋ง | WordPress ๊ณต์ ์คํํฐ ํ ๋ง |
๋ค์ ๋จ๊ณ ํ์ต ์ฃผ์
๐ ์ค๊ธ ๊ฐ๋ฐ์๋ก ์ฑ์ฅํ๊ธฐ
1. Gutenberg ๋ธ๋ก ๊ฐ๋ฐ
- React ๊ธฐ๋ฐ ์ปค์คํ
๋ธ๋ก ๋ง๋ค๊ธฐ
- ๋ธ๋ก ํจํด๊ณผ ๋ธ๋ก ๋ณํ
2. WooCommerce ํ์ฅ
- ์ปค์คํ
์ ํ ํ์
๊ฐ๋ฐ
- ๊ฒฐ์ ๊ฒ์ดํธ์จ์ด ํตํฉ
3. Multisite ๊ฐ๋ฐ
- ๋คํธ์ํฌ ์ ์ฒด ํ๋ฌ๊ทธ์ธ
- ์ฌ์ดํธ๋ณ ์ค์ ๊ด๋ฆฌ
4. WordPress as Headless CMS
- REST API ๊ณ ๊ธ ํ์ฉ
- React, Vue, Next.js์ ํตํฉ
5. ์ฑ๋ฅ ์ต์ ํ ์ฌํ
- ๊ฐ์ฒด ์บ์ฑ (Redis, Memcached)
- CDN ํตํฉ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ต์ ํ
6. ๋ณด์ ๊ฐํ
- Two-Factor Authentication
- ๋ณด์ ๊ฐ์ฌ ๋ฐ ๋ชจ๋ํฐ๋ง
- OWASP Top 10 ๋์
์ปค๋ฎค๋ํฐ ์ฐธ์ฌ
๐ค WordPress ์ปค๋ฎค๋ํฐ
๊ตญ๋ด ์ปค๋ฎค๋ํฐ:
- WordPress Korea ํ์ด์ค๋ถ ๊ทธ๋ฃน
- ์๋ํ๋ ์ค ํ๊ตญ ์ฌ์ฉ์ ๋ชจ์
- ๊ฐ์ข
๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ์ WordPress ์ฑ๋
๊ธ๋ก๋ฒ ์ปค๋ฎค๋ํฐ:
- WordPress.org Support Forums
- WordPress Stack Exchange
- WordPress Slack
- WordCamp (์ ์ธ๊ณ WordPress ์ปจํผ๋ฐ์ค)
๊ธฐ์ฌํ๊ธฐ:
- WordPress Core ๊ธฐ์ฌ
- ํ๋ฌ๊ทธ์ธ/ํ
๋ง ๋ฒ์ญ
- ๋ฌธ์ ์์ฑ ๋ฐ ๊ฐ์
- ์ปค๋ฎค๋ํฐ ์ง์
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ๐
WordPress ํ๋ฌ๊ทธ์ธ๊ณผ ํ
๋ง ๊ฐ๋ฐ, ๊ทธ๋ฆฌ๊ณ ์ปค์คํ
ํฌ์คํธ ํ์
ํ์ฉ๋ฒ๊น์ง ์ ๋ง ๋ง์ ๋ด์ฉ์ ๋ค๋ค์ด. ์ฒ์์๋ ๋ณต์กํด ๋ณด์ผ ์ ์์ง๋ง, ํ๋์ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผํ๋ค ๋ณด๋ฉด ์ด๋์ ์์ ๋ง์ WordPress ์ฌ์ดํธ๋ฅผ ์์ ์์ฌ๋ก ์ปค์คํฐ๋ง์ด์งํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ!
๊ธฐ์ตํด์ผ ํ ํต์ฌ ํฌ์ธํธ๋ฅผ ์ ๋ฆฌํด๋ณผ๊ฒ:
๐ฏ ํต์ฌ ์์ฝ
1. WordPress๋ PHP ๊ธฐ๋ฐ์ ๊ฐ๋ ฅํ CMS
- ํ
๋ง๋ ์ธ๊ด, ํ๋ฌ๊ทธ์ธ์ ๊ธฐ๋ฅ์ ๋ด๋น
- ํ
(Hook) ์์คํ
์ผ๋ก ์ ์ฐํ๊ฒ ํ์ฅ ๊ฐ๋ฅ
2. ์ปค์คํ
ํฌ์คํธ ํ์
์ผ๋ก ๋ค์ํ ์ฝํ
์ธ ๊ด๋ฆฌ
- register_post_type()์ผ๋ก ๋ฑ๋ก
- ์ปค์คํ
ํ์๋
ธ๋ฏธ๋ก ๋ถ๋ฅ ์ฒด๊ณ ๊ตฌ์ถ
- ๋ฉํ๋ฐ์ค๋ก ์ถ๊ฐ ์ ๋ณด ์
๋ ฅ
3. WP_Query๋ก ๊ฐ๋ ฅํ ๋ฐ์ดํฐ ์กฐํ
- ๋ค์ํ ์กฐ๊ฑด์ผ๋ก ํํฐ๋ง
- ํ์๋
ธ๋ฏธ์ ๋ฉํ ์ฟผ๋ฆฌ ํ์ฉ
- ์ฑ๋ฅ์ ์ํ ์ต์ ํ ํ์
4. REST API๋ก ํ๋์ ์ธ ์น ์ ํ๋ฆฌ์ผ์ด์
๊ตฌ์ถ
- show_in_rest๋ก ์๋ ์๋ํฌ์ธํธ ์์ฑ
- register_rest_field()๋ก ์ปค์คํ
ํ๋ ์ถ๊ฐ
- ํ๋ก ํธ์๋ ํ๋ ์์ํฌ์ ํตํฉ ๊ฐ๋ฅ
5. ๋ณด์๊ณผ ์ฑ๋ฅ์ ํญ์ ์ต์ฐ์
- ์
๋ ฅ ๊ฒ์ฆ๊ณผ ์ถ๋ ฅ ์ด์ค์ผ์ดํ
- Nonce์ ๊ถํ ํ์ธ
- ์บ์ฑ๊ณผ ์ฟผ๋ฆฌ ์ต์ ํ
WordPress ๊ฐ๋ฐ์ ๋จ์ํ ์ฝ๋๋ฅผ ์์ฑํ๋ ๊ฒ์ ๋์ด์, ์ฌ์ฉ์ ๊ฒฝํ์ ๊ฐ์ ํ๊ณ ๋น์ฆ๋์ค ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์ฐฝ์์ ์ธ ์์
์ด์ผ. ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ์ด๋ฐ ๊ธฐ์ ๋ค์ด ์ค์ ๋ก ํ์ฉ๋๊ณ ์๊ณ , ์ฌ๋ฌ๋ถ๋ ์ถฉ๋ถํ ๋ฉ์ง ํ๋ก์ ํธ๋ฅผ ๋ง๋ค ์ ์์ด!
๊ฐ๋ฐํ๋ค๊ฐ ๋งํ๋ ๋ถ๋ถ์ด ์์ผ๋ฉด WordPress ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ์ ์ธ๊ณ ์๋ง์ ๊ฐ๋ฐ์๋ค์ด ๊ธฐ๊บผ์ด ๋์์ค ๊ฑฐ์ผ. ๊ทธ๋ฆฌ๊ณ ์ธ์ ๊ฐ๋ ์ฌ๋ฌ๋ถ๋ ๋ค๋ฅธ ์ฌ๋๋ค์ ๋์์ฃผ๋ ๋ฉ์ง ๊ฐ๋ฐ์๊ฐ ๋์ด ์์ ๊ฑฐ๋ผ๊ณ ๋ฏฟ์ด! ๐ช
์ด ๊ธ์ด WordPress ๊ฐ๋ฐ ์ฌ์ ์ ๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋ผ. ๊ณ์ ๋ฐฐ์ฐ๊ณ , ์คํํ๊ณ , ๋ง๋ค์ด๊ฐ๋ฉด์ ์ฑ์ฅํ๊ธธ ์์ํ ๊ฒ! ํ์ดํ
! ๐โจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.