無論是直接使用插件,還是參考代碼,Custom Post Type UI都很有參考作用,下載鏈接:
https://wordpress.org/plugins/custom-post-type-ui/
在functions.php上加入以下代碼:
~~~
// custom post type
function awesome_custom_post_type(){
$labels = array(
'name' => 'Porfolio',
'singular_name' =>'Portfolio',
'add_new' => 'Add Item',
'all_items' => 'All Items',
'add_new_item' => 'Edit Item',
'new_item' => 'New Item',
'view_item' => 'View Items',
'search_item' => 'Search Portfolio',
'not_found' => 'No items fouond',
'not_found_in_trash' => 'No items found in trash',
'parent_item_colon' => 'Parent Item'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'menu_icon' =>'dashicons-welcome-write-blog',
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'support' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'revisions',
),
'taxonomies' => array('category', 'post_tag'),
'menu_position' => 5,
'exclude_from_search' => false
);
register_post_type('portfolio', $args);
}
add_action('init','awesome_custom_post_type');
~~~
admin界面會多出和文章一樣格式的Porfolio(作品):

創建一個專頁來顯示作品集:
創建page-portfolio.php,加上以下代碼:
~~~
<?php
/*
* Template Name: Portfolio Template
*/
?>
<?php get_header(); ?>
<?php
$args=array('post_type' => 'portfolio', 'post_per_page' => 3);
$loop=new WP_Query($args);
if($loop->have_post()):
while(have_posts()): the_post(); ?>
<?php get_template_part('content', 'archive'); ?>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
~~~
在創建的頁面上,選擇Portfolio Template作為頁面模板。
- WordPress平臺的網站開發
- 電商主題開發
- WooCommerce主題開發優化部分
- 首頁開發
- WooCommerce
- 判斷用戶是否登錄
- WordPress Menu
- WooCommerce PayPal Checkout Gateway
- 頁面和文章
- 調用產品和文章
- 判斷屬于哪個頁面
- 相關文章
- 消除文章分享按鈕集底部的文字
- wordpress主題模板和主題開發
- wordpress主題準備
- wordpress主題文件結構
- 豪源主題
- WooCommerce SEO
- 插件開發
- wordpress二次開發
- theme基本顯示
- menu調用
- 分拆為header.php和footer.php
- 頁面、文章樣式選擇顯示
- 面包屑導航 Breadcrumb
- 特色圖
- 閱讀次數統計
- 分頁功能
- Advanced Custom Fields
- Custom Post Type UI
- post type
- 小工具
- 小工具調用
- shortcode
- 文章循環輸出
- 標題和文章限制字數輸出顯示
- WordPress主題theme1開發
- wordpress搭建多站點
- wordpress常用函數
- wordpress循環代碼
- Woocommerce
- Woocommerce支持
- WordPress插件開發
- wordpress會員插件
- WordPress插件使用
- WordPress插件集
- WordPress的核心
- Wordpress原理
- Wordpress要點
- WordPress網站搬家
- WPML
- 服務器
- Cloud 9
- test
- 網站