当前位置: 首页 » 网站建设 » wordpress教程 » 正文

wordpress自定义文章类型功能添加

发布时间:2025-01-16 以下文章来源于网友投稿,内容仅供参考!

我们在做wordpress企业站的时候常常需要增加自定义文章类型

类似于产品中心,案例中心,新闻资讯

不同分类需要调用不同的模板,所以我们可以通过自定义文章类型来定义

下面以添加产品中心来举例:

1.在主题函数functions.php中添加一下代码

area data-settings="dblclick" readonly >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"dblclick" readonly >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));}area>161718192021222324252627282930313233add_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
如果要在模板页面调用自定义文章类型的分类文章列表就需要用到以下代码;

area data-settings="dblclick" readonly ><?php query_posts('post_type=product&showposts=6'); ?><?php while (have_posts()) : the_post(); ?> <div ><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 ><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p></div><?php endwhile; ?> area>12345678910111213<?php query_posts('post_type=product&showposts=6'); ?><?php while (have_posts()) : the_post(); ?> <div ><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 ><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p></div><?php endwhile; ?>

  • • 开启wds是什么意思?无线路由器wds是怎么开启?

    开启wds是什么意思?WDS是英文Wireless Distribution System的简称,中文名称是:无线分布式系统。WDS功能就是一种帮助无线基站与

  • • 系统boot是什么意思?电脑出现boot manager怎么办?

    系统boot是什么意思1、开机后我们连续按启动热键,进入bios界面,我们就可以看到boot了。2、boot有启动的意思,在电脑中就是指电

  • • win10系统msconfig无法正常启动怎么办?win10系统msconfig怎么设置最

    msconfig打不开解决办法:1.先打开电脑开始菜单,在操作窗口输入regedit,打开注册表编辑器。然后将HKEY_LOCAL_MACHINE\SOFTWARE

  • • 金士顿u盘怎么写保护?金士顿U盘恢复出厂设置怎么操作?

    金士顿u盘怎么写保护?方法一:如果你的U盘如我简介中说的那样,有一个自带的物理写保护的小 开关 ,就观察一下是不是已经将开关

  • • 苹果AirPods Pro 2发布 搭载H2芯片降噪能力翻倍

    9月8日凌晨,苹果正式发布第二代主动降噪耳机AirPods Pro 2,搭载H2芯片,降噪能力翻倍,而且续航也飚至30小时。得益于全新的H2

  • biubiu加速器
    九游优盟游戏推广平台
    九游推广联盟
    digdig游戏入口
    4999小游戏大全
    九游游戏网
    站长素材
    植物大战僵尸杂交免费版
    站长之家
    测速网在线测网速
    354211邮编查询,354211邮政编码查询
    354209邮编查询,354209邮政编码查询
    353132邮编查询,353132邮政编码查询
    354215邮编查询,354215邮政编码查询
    353121邮编查询,353121邮政编码查询
    354213邮编查询,354213邮政编码查询
    353125邮编查询,353125邮政编码查询
    354201邮编查询,354201邮政编码查询
    353101邮编查询,353101邮政编码查询
    354200邮编查询,354200邮政编码查询