CMB2 Attached Posts 项目教程

CMB2 Attached Posts 项目教程

cmb2-attached-postsCustom field for CMB2 for attaching posts to a page.项目地址:https://gitcode.com/gh_mirrors/cm/cmb2-attached-posts

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

CMB2 Attached Posts 项目的目录结构如下:

cmb2-attached-posts/
├── css/
│   └── attached-posts-field.css
├── js/
│   └── attached-posts-field.js
├── attached-posts-field.php
├── composer.json
├── example-field-setup.php
├── init.php
├── LICENSE
├── README.md
├── attached-posts-field.png
└── attached-posts-search.gif

目录结构介绍

  • css/: 包含项目的样式文件。
  • js/: 包含项目的JavaScript文件。
  • attached-posts-field.php: 核心文件,定义了附加帖子字段的功能。
  • composer.json: Composer 配置文件,用于依赖管理。
  • example-field-setup.php: 示例文件,展示了如何设置附加帖子字段。
  • init.php: 初始化文件,用于项目的初始化设置。
  • LICENSE: 项目的许可证文件。
  • README.md: 项目的说明文档。
  • attached-posts-field.png: 项目截图。
  • attached-posts-search.gif: 项目功能演示动画。

2. 项目的启动文件介绍

项目的启动文件是 init.php。该文件负责初始化 CMB2 Attached Posts 插件,并确保其正确加载和运行。

init.php 文件内容概述

<?php
/**
 * Initialize the CMB2 Attached Posts Field.
 */
require_once 'attached-posts-field.php';

该文件通过 require_once 引入了 attached-posts-field.php 文件,确保核心功能文件被加载。

3. 项目的配置文件介绍

项目的配置文件主要是 composer.jsonexample-field-setup.php

composer.json 文件内容概述

{
    "name": "cmb2/cmb2-attached-posts",
    "description": "Custom field for CMB2 for attaching posts to a page",
    "license": "GPL-2.0-or-later",
    "authors": [
        {
            "name": "CMB2 Team",
            "email": "cmb2@example.com"
        }
    ],
    "require": {}
}

该文件定义了项目的名称、描述、许可证和作者信息。require 部分用于声明项目的依赖。

example-field-setup.php 文件内容概述

<?php
/**
 * Example of how to set up a CMB2 field for attaching posts.
 */
add_action( 'cmb2_admin_init', 'cmb2_attached_posts_field_metabox' );
function cmb2_attached_posts_field_metabox() {
    $cmb = new_cmb2_box( array(
        'id'            => 'attached_posts_metabox',
        'title'         => __( 'Attached Posts', 'cmb2' ),
        'object_types'  => array( 'page' ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
    ) );

    $cmb->add_field( array(
        'name'    => __( 'Attached Posts', 'cmb2' ),
        'desc'    => __( 'Drag posts from the left column to the right column to attach them to this page.', 'cmb2' ),
        'id'      => 'attached_posts',
        'type'    => 'attached_posts',
        'options' => array(
            'query_args' => array(
                'post_type' => 'post', // Post type
            ),
        ),
    ) );
}

该文件展示了如何设置 CMB2 附加帖子字段,包括如何创建元框和添加字段。


以上是 CMB2 Attached Posts 项目的详细教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望对您有所帮助!

cmb2-attached-postsCustom field for CMB2 for attaching posts to a page.项目地址:https://gitcode.com/gh_mirrors/cm/cmb2-attached-posts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

滕娴殉

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

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

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

打赏作者

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

抵扣说明:

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

余额充值