-
Notifications
You must be signed in to change notification settings - Fork 0
Post Types
WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.
워드프레스는 다양한 타입의 컨텐츠를 저장하고 보여줄 수 있습니다. 그런 컨텐츠 중 하나의 아이템을 보통 포스트 라고 부릅니다. (비록 'post' 라는 같은 이름의 포스트 타입이 있긴 하지만요.) 내부적으로 모든 포스트 타입은 같은 장소, wp_posts 데이터베이스 테이블, 에 저장되지만, post_type 이라는 컬럼으로 구분할 수 있습니다.
WordPress 3.0 gives you the capability to add your own custom post types and to use them in different ways.
워드프레스 3.0에서는 당신이 직접 만든 커스텀 포스트 타입을 추가하고, 이를 다양한 방식으로 이용할 수 있게 되었습니다.
There are five post types that are readily available to users or internally used by the WordPress installation by default :
Post (Post Type: 'post')
Page (Post Type: 'page')
Attachment (Post Type: 'attachment')
Revision (Post Type: 'revision')
Navigation menu (Post Type: 'nav_menu_item')
Post in WordPress is a post type that is typical for and most used by blogs. Posts are normally displayed in a blog in reverse sequential order by time (newest posts first). Posts are also used for creating the feeds.
워드프레스의 post 는 블로그 용도로 가장 많이 사용되는 전형적인 포스트 타입입니다. Post 는 일반적으로 블로그에서 시간 역순(최근 글이 먼저)으로 노출됩니다. Post 는 또한 feeds 를 만드는 데 사용됩니다.
Page in WordPress is like post, but it lives outside the normal time-based listings of posts. Pages can use different page templates to display them. Pages can also be organized in a hierarchical structure, with pages being parents to other pages, but they normally cannot be assigned categories and tags. If permalinks are enabled, the permalink of a page is always composed solely of the main site URL and the user-friendly and URL-valid names (also referred to as slug) of the page and its parents if they exist. See the Pages article for more information about the differences.
워드프레스의 Page 는 post 와 비슷합니다. 그러나 그것은 일반 post의 시간 기반 목록 바깥에 있습니다. page 는 다른 페이지 템플릿을 그것들을 보여주는 데 사용할 수 있습니다. Page 는 또한 다른 페이지의 부모가 되는 것을 통해 계층 관계를 가질 수 있는데, (그것은 일반 페이지인지 부모타입의 페이지인지는 잘 모르겠지만) 일반적으로 카테고리나 태그를 가질 수 없습니다. 퍼머링크가 enable 되면, 페이지의 퍼머링크는 항상 메인 사이트 URL에 단독으로 구성되고, user-friendly 하고, 페이지의 URL-valid 한 이름이고, ...
Attachment is a special post that holds information about a file uploaded through the WordPress media upload system, such as its description and name. For images, this is also linked to metadata information, stored in the wp_postmeta table, about the size of the images, the thumbnails generated from the images, the location of the image files, the HTML alt text, and even information obtained from EXIF data embedded in the images.
attachment 는 워드프레스 미디어 업로드 시스템에 의해 업로드된 파일의 정보를 가지고 있는 특별한 포스트입니다. 파일 설명이나 이름 같은거 말이죠. 이미지를 예로 들면, 이것은 또한 메타데이터 정보로 링크되어 있는데, 그것은 wp_postmeta 테이블에 저장되어 있는, 이미지의 사이즈에 관한 정보, 이미지에서 만들어진 썸네일, 이미지 파일의 위치, HTML alt 텍스트, 이미지에 첨부된 EXIF 데이터에서 가져온 정보 등입니다.
Revision is used to hold a draft post as well as any past revisions of a published post. Revisions are basically identical to the published post which they belong to, but have that post set as their parent using the post_parent column of the wp_posts table.
Navigation Menu is a type that holds information about a single item in the WordPress navigation menu system. These are the first examples of entries in the wp_posts table to be used for something other than an otherwise displayable content on the blog.
Custom post types are new post types you can create. A custom post type can be added to WordPress via the
register_post_type()function. This function allows you to define a new post type by its labels, supported features, availability and other specifics.
커스텀 포스트 타입은 당신이 만들 수 있는 새로운 포스트 타입입니다. 커스텀 포스트 타입은 register_post_type() 함수로 워드프레스에 추가될 수 있습니다. 이 함수는 당신이 새로운 포스트 타입을 그 라벨과 지원되는 기능과 다른 스펙 등으로 정의할 수 있게 해 줍니다.
Note that you must call register_post_type() before the admin_menu and after the after_setup_theme action hooks. A good hook to use is the init hook.
당신은 register_post_type 함수를 admin_menu 와 after_setup_theme 액션 hook 사이에 호출해야 함을 명심하세요. 사용하기에 좋은 hook 는 init hook 입니다.
Here's a basic example of adding a custom post type:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
)
);
}
This creates a post type named Product identified as acme_product. The
register_post_type()function receives two major arguments. The first one is labels which define the name of the post type in both plural and singular forms. The second one is public which is a predefined flag to show the post type on the administration screens and to make it show up in the site content itself, if it's queried for.
이것은 이름은 Product 이고 acme_product 라는 아이디를 가진 포스트타입을 만듭니다. register_post_type() 함수는 두개의 중요한 파라메터를 받습니다. 첫번째는 labels 인데, 포스트타입의 이름을 복수형과 단수형으로 받는 값입니다. 두번째는 public 인데, 관리자 화면에 포스트타입을 보여주고 그것을 사이트 컨텐츠 자체로 만드는 것으로 정의된 플래그입니다.
The second one is public which is a predefined flag to show the post type on the administration screens and to make it show up in the site content itself, if it's queried for.
There are many more arguments you can pass to the register_post_type() function, to do things like set up hierarchy (to behave like pages), show the new post type in searches, change the URLs of the new posts, and hide or show meta boxes in the post edit screen. These parameters are optional, and you can use them to configure your post type on a detailed level.
register_post_type() 함수에 넘길 수 있는 파라메터는 더 많습니다, 페이지처럼 동작하도록 계층 구조로 하게 하는 것?, 검색할 때 새 포스트 타입을 보여주는 것, 새 포스트의 URL을 바꾸는 것, 그리고 포스트 수정 화면에 메타 박스를 보이거나 숨기는 것 등 이 있습니다. 이 파라메터들은 optional 이고, 포스트 타입을 좀더 디테일하게 설정할 때 사용할 수 있습니다.
In order to avoid breaking a site on theme switching, try to define custom post types as a plugin, or, better as a Must Use Plugins. This way you won't force users into using a certain theme.
테마가 스위칭 되었을 때 사이트가 부서지는 것을 막기 위해, 커스텀 포스트 타입을 플러그인으로 정의하는 것을 시도하세요. 혹은, Must use Plugin 으로 정의하는 게 더 좋을 겁니다. 이렇게 하면 당신은 사용자가 특정 테마를 사용하는 것을 강제하지 않게 됩니다.
While it is convenient to use a simple custom post type identifier like product which is consistent with the identifiers of the default post types (post, page, revision, attachment and nav_menu_item), it is better if you prefix your identifier with a short namespace that identifies your plugin, theme or website that implements the custom post type.
디폴트 포스트 타입(post, page, revision, attachment and nav_menu_item)과 유사하게 product 처럼 단순한 커스텀 타입 아이디를 사용하는 것이 간편하겠지만, 당신의 아이디에는 커스텀 포스트 타입을 구현한 당신의 플러그인이나 테마나 웹사이트의 짧은 네임스페이스를 prefix 로 붙이는 것이 더 좋습니다.
For example:
- acme_product or aw_product for products post type used by a hypothetical ACMEWidgets.com website.
- ACMEWidgets.com 라는 가상의 웹사이트에서 product 포스트 타입을 제공한다면 acme_product 나 aw_product 를 씁니다.
- eightfold_product or eft_product for products post type provided by a hypothetical EightFold theme.
- EightFold 라는 가상의 테마에서 product 포스트 타입을 제공한다면 eightfold_product 나 eft_product 를 씁니다.
- ai1m_product for products post type provided by a hypothetical All-in-One Merchant plugin.
- All-in-One Merchant 라는 가상의 플러그인에서 제공하는 product 포스트 타입이라면 ai1m_product 를 씁니다.
Without namespacing your custom post type identifier, other post types in your website will more likely conflict with custom post types defined in a theme you fall in love with later or a plugin you realize that you absolutely need to use. Or if you are developing custom post types or themes there is a much greater chance your plugin or theme will conflict with custom post types defined in other plugins or themes and/or custom post types defined in your prospective user's website. Namespacing your custom post type identifier will not guarantee against conflicts but will certainly minimize their likelihood.
당신의 커스텀 포스트 타입 아이디에 네임스페이스를 사용하지 않으면, other post types in your website will more likely conflict with custom post types defined in a theme you fall in love with later or a plugin you realize that you absolutely need to use. 또는 당신이 플러그인이나 테마를 개발고 있는 중이라면 > 더 큰 기회가 있는데 > 당신의 플러그인이나 테마가 다른 플러그인이나 테마에서 정의한 커스텀 포스트 타입과 충돌할, 혹은/그리고 당신의 미래의 사용자의 웹사이트에서 정의한. 당신의 커스텀 포스트 타입 아이디에 네임스페이스를 붙이는 것은 충돌을 피할 것을 보장하지는 않지만, 그럴 가능성을 확실히 낮춥니다.
Do pay close attention to not having your custom post type identifier exceed 20 characters though, as the post_type column in the database is currently a VARCHAR field of that length.
Although the core development team has yet to make a final decision on this, it has been proposed on the wp-hackers mailing list that future core post type identifiers will be namespaced with wp_, i.e. if the core team decides to add an event post type then according to this suggestion they would use the wp_event identifier. Even though this has not been finalized, it will be a good idea to avoid any custom post types whose identifier begins with wp_. 코어 개발자 팀은 아직 이것에 대한 최종 결정을 내리지 않았(렸?)지만, 그것은 이미 wp-hackers 메일링리스트에서 제안되었다 > 미래의 코어 포스트 타입 아이디는 wp_로 네임스페이스가 붙을 것라고. i.e. 만약 코어 팀이 이벤트 포스트 타입을 추가하기로 결정한다면 이 제안을 따라 그들은 wp_event 아이디를 사용할 것이다. 이것은 아직 완료되지 않았더라도 그것은 좋은 아이디어이다 > 커스텀 포스트 타입이 wp_ 로 시작하는 아이디를 피하는 것은.
When a custom post type is created like in the example above, it gets a new top-level administration menu to create and manage posts of that new post type. New administration screens will be accessible from that menu, such as post edit screen where you will have a full post editor and everything that comes along with it according to what features you set that your custom post type should support by the supports argument of the register_post_type() function. You can customize the screens with several action and filter hooks, see this Custom Post Type Snippets post by Yoast for an explanation and code examples on how to change a custom post type overview screen.
커스텀 포스트 타입이 위의 예제처럼 만들어지면, 그것은 새로운 최고 레벨 관리자 메뉴를 얻는다. > 새 타입의 포스트를 만들고 수정하는 만들고 수정하는. 새 관리자 화면이 그 메뉴로부터 접근 가능해지는데, 포스트 수정 화면 > 당신이 전체 포스트 에디터를 가질 그리고 모든 것은 ....
URLs A custom post type will also get its own slug within the site URL structure. In the above example, a post of this product custom post type can be displayed at http://example.com/acme_product/%product_name% where acme_product is the slug of your custom post type and %product_name% is the slug of your particular product, so a permalink could be e.g. http://example.com/product/foobrozinator. You can see this permalink appear on the edit post screen for your custom post type, just like with default post types.
URLs of Namespaced Custom Post Types Identifiers
When you namespace a custom post type identifier and still want to use a clean URL structure, you need to set the rewrite argument of the register_post_type() function. For example, assuming the ACME Widgets example from above:
add_action( 'init', 'create_posttype' ); function create_posttype() { register_post_type( 'acme_product', array( 'labels' => array( 'name' => __( 'Products' ), 'singular_name' => __( 'Product' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'products'), ) ); } The above will result in post URLs in the form http://example.com/products/%product_name%. Note that we used a plural word for the slug here which is a form that some people prefer because it implies a more logical URL for a page that embeds a list of products, i.e. http://example.com/products/.
Also note that using a generic slug like products here can potentially conflict with other plugins or themes that use the same slug, but most people would dislike longer and more obscure URLs like http://example.com/acme_products/foobrozinator and resolving the URL conflict between two plugins is easier simply because the URL structure is not stored persistently in each post's database record the same way custom post type identifiers are stored.
Custom Post Type Templates The WordPress theme system supports custom templates for custom post types too. A custom template for a single display of posts belonging to a custom post type is supported since WordPress Version 3.0 and the support for a custom template for an archive display was added in Version 3.1.
Note: In some cases, the permalink structure must be updated in order for the new template files to be accessed when viewing posts of a custom post type. To do this, go to Administration Panels > Settings > Permalinks, change the permalink structure to a different structure, save the changes, and change it back to the desired structure.
Template Files
In the same way single posts and their archives can be displayed using the single.php and archive.php template files, respectively,
single posts of a custom post type will use single-{post_type}.php and their archives will use archive-{post_type}.php and if you don't have this post type archive page you can pass BLOG_URL?post_type={post_type} where {post_type} is the $post_type argument of the register_post_type() function.
So for the above example, you could create single-acme_product.php and archive-acme_product.php template files for single product posts and their archives.
Alternatively, you can use the is_post_type_archive() function in any template file to check if the query shows an archive page of a given post types(s), and the post_type_archive_title() to display the post type title.
Querying by Post Type In any template file of the WordPress theme system, you can also create new queries to display posts from a specific post type. This is done via the post_type argument of the WP_Query object.
Example:
$args = array( 'post_type' => 'product', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '
Custom Post Types in the Main Query Registering a custom post type does not mean it gets added to the main query automatically.
If you want your custom post type posts to show up on standard archives or include them on your home page mixed up with other post types, use the pre_get_posts action hook.
// Show posts of 'post', 'page' and 'movie' post types on home page add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( 'post_type', array( 'post', 'page', 'movie' ) ); return $query; } Function Reference Post Types: register_post_type(), add_post_type_support(), remove_post_type_support(), post_type_supports(), post_type_exists(), set_post_type(), get_post_type(), get_post_types(), get_post_type_object(), get_post_type_capabilities(), get_post_type_labels(), is_post_type_hierarchical(), is_post_type_archive(), post_type_archive_title()
More Information Custom post type standards WordPress Post Type Generator Showing custom post types on your home/blog page Podcast Presentation: WordPress Custom Post Types Both Slides and Audio on Custom Post Types Custom Post Types in WordPress 3.0 Extending Custom Post Types in WordPress 3.0 Change Order for Custom Post Types in WordPress 3.0 and up Custom Post Type Example Custom Post Type Snippets Category: Advanced Topics