开源项目 `custom-post-type-permalinks` 使用教程

开源项目 custom-post-type-permalinks 使用教程

custom-post-type-permalinksEdit the permalink of custom post type !项目地址:https://gitcode.com/gh_mirrors/cu/custom-post-type-permalinks

1. 项目的目录结构及介绍

custom-post-type-permalinks/
├── assets/
│   ├── css/
│   ├── js/
│   └── img/
├── includes/
│   ├── class-custom-post-type-permalinks.php
│   ├── class-custom-post-type-permalinks-admin.php
│   └── class-custom-post-type-permalinks-util.php
├── languages/
│   └── custom-post-type-permalinks.pot
├── custom-post-type-permalinks.php
└── readme.txt
  • assets/: 包含项目的静态资源文件,如CSS、JavaScript和图片。
  • includes/: 包含项目的主要功能类文件。
    • class-custom-post-type-permalinks.php: 主类文件,处理自定义文章类型的固定链接。
    • class-custom-post-type-permalinks-admin.php: 管理后台类文件,处理后台设置。
    • class-custom-post-type-permalinks-util.php: 工具类文件,提供辅助功能。
  • languages/: 包含项目的语言文件,支持多语言。
  • custom-post-type-permalinks.php: 项目的主启动文件。
  • readme.txt: 项目的说明文档。

2. 项目的启动文件介绍

custom-post-type-permalinks.php 是项目的主启动文件,负责初始化插件并加载必要的文件。以下是该文件的主要内容:

<?php
/*
Plugin Name: Custom Post Type Permalinks
Plugin URI: https://github.com/torounit/custom-post-type-permalinks
Description: Add support of permalinks to custom post types.
Version: 1.0
Author: Toro_Unit
Author URI: https://torounit.com
Text Domain: custom-post-type-permalinks
Domain Path: /languages
*/

require_once( dirname( __FILE__ ) . '/includes/class-custom-post-type-permalinks.php' );
require_once( dirname( __FILE__ ) . '/includes/class-custom-post-type-permalinks-admin.php' );
require_once( dirname( __FILE__ ) . '/includes/class-custom-post-type-permalinks-util.php' );

$custom_post_type_permalinks = new Custom_Post_Type_Permalinks();
$custom_post_type_permalinks->init();
  • Plugin Name: 插件的名称。
  • Plugin URI: 插件的官方网站。
  • Description: 插件的描述。
  • Version: 插件的版本号。
  • Author: 插件的作者。
  • Text Domain: 插件的文本域,用于多语言支持。
  • Domain Path: 语言文件的路径。

3. 项目的配置文件介绍

项目的配置主要通过 class-custom-post-type-permalinks.phpclass-custom-post-type-permalinks-admin.php 文件进行。以下是 class-custom-post-type-permalinks.php 的部分代码:

class Custom_Post_Type_Permalinks {
    public function init() {
        add_action( 'init', array( $this, 'rewrite_rules' ) );
        add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 );
        add_filter( 'term_link', array( $this, 'term_link' ), 10, 3 );
    }

    public function rewrite_rules() {
        // 添加自定义重写规则
    }

    public function post_type_link( $link, $post ) {
        // 修改自定义文章类型的链接
    }

    public function term_link( $termlink, $term, $taxonomy ) {
        // 修改自定义分类法的链接
    }
}
  • init(): 初始化方法,添加必要的动作和过滤器。
  • rewrite_rules(): 添加自定义重写规则。
  • post_type_link(): 修改自定义文章类型的链接。
  • term_link(): 修改自定义分类法的链接。

通过这些配置文件,可以灵活地修改和扩展自定义文章类型和分类法的固定链接。

custom-post-type-permalinksEdit the permalink of custom post type !项目地址:https://gitcode.com/gh_mirrors/cu/custom-post-type-permalinks

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丁战崇Exalted

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值