程序源码收集
酱茄Free小程序开源版-源码下载/官网
酱茄企业官网小程序(多端开源版小程序源码下载)-酱茄小程序
酱茄Free主题- 酱茄WordPress主题官网/主题下载
MinDoc 首页、文档和下载 - Go 实现的接口在线文档管理系统 - OSCHINA - 中文开源技术交流社区
Aragorn 一款利用对象存储SDK进行上传的图床工具
【主题开发】WordPress只需3步将wp-clean-up插件集成到主题
全代码实现 WordPress 分类目录和标签添加新的自定义字段 - 露兜即刻
wordpress 自定义文章类型功能添加 - WordPress 主题
本文档使用 MrDoc 发布
-
+
home page
wordpress 自定义文章类型功能添加 - WordPress 主题
> 本文由 [简悦 SimpRead](http://ksria.com/simpread/) 转码, 原文地址 [www.wazhuti.com](http://www.wazhuti.com/716.html) **摘要:**我们在做 wordpress 企业站的时候常常需要增加自定义文章类型 类似于产品中心,案例中心,新闻资讯 不同分类需要调用不... 我们在做 wordpress 企业站的时候常常需要增加自定义文章类型 类似于产品中心,案例中心,新闻资讯 不同分类需要调用不同的模板,所以我们可以通过自定义文章类型来定义 下面以添加产品中心来举例: 1. 在主题函数 functions.php 中添加一下代码 ``` add_action( 'init', 'create_product_post_types' ); function create_product_post_types() { register_post_type( 'product', array( 'labels' => array( 'name' => __( '产品中心' ), 'singular_name' => __( '产品中心' ), 'add_new' => __( '添加' ), 'add_new_item' => __( '创建' ), //'edit' => __( 'Edit' ), // 'edit_item' => __( 'Edit Super Duper' ), 'new_item' => __( '所有产品' ), //'view' => __( 'View Super Duper' ), //'view_item' => __( 'View Super Duper' ), 'search_items' => __( '搜索' ), 'not_found' => __( '没有搜索到' ), 'not_found_in_trash' => __( '没有搜索到' ), //'parent' => __( 'Parent Super Duper' ), ), 'public' => true, //'rewrite' => array('slug' => 'job'), //'menu_position' => 15, 'supports' => array( 'title', 'editor','thumbnail','excerpt', 'author' ), //'taxonomies' => array( '' ), //'menu_icon' => plugins_url( 'images/image.png', __FILE__ ), 'has_archive' => true, ) ); } ``` 2. 增加 wordpress 自定义文章的分类功能 ``` add_action( 'init', 'create_product_taxonomies', 0 ); function create_product_taxonomies() { register_taxonomy( 'product_genre', 'product', array( 'labels' => array( 'name' => '产品分类', 'add_new_item' => '添加分类', 'new_item_name' => "新分类" ), 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => true ) ); } ``` wordpress 自定义文章类型的调用方法,只需要新增分类页 archive-product.php 和文章页 single-product.php 如果要在模板页面调用自定义文章类型的分类文章列表就需要用到以下代码; ``` <?php query_posts('post_type=product&showposts=6'); ?> <?php while (have_posts()) : the_post(); ?> <div class="col-sm-3 col-md-2 col-mm-6 product_img"> <a href="<?php the_permalink() ?>"> <?php if ( has_post_thumbnail() ) { ?> <?php the_post_thumbnail(array(270,270)); ?> <?php } else {?> <img src="<?php bloginfo('template_url'); ?>/images/554838fc3e9f9.jpg" /> <?php } ?> </a> <p class="product_title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> </div> <?php endwhile; ?> ```
似最初
Sept. 7, 2021, 5:33 p.m.
转发文档
Collection documents
Last
Next
手机扫码
Copy link
手机扫一扫转发分享
Copy link
Markdown文件
share
link
type
password
Update password