定制 frojd/frojd-segments 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

frojd/frojd-segments

最新稳定版本:v1.0.2

Composer 安装命令:

composer require frojd/frojd-segments

包简介

README 文档

README

Plugin to handle segment metaboxes where the editor can drag'n'drop articles from a list of available articles, into a sorted list which then can be used in different ways in the theme. This functionality is mainly built from a "featured articles" point of view where the editor can e.g. select related articles for a specific article.

Using a hook included in the theme, the segment metabox can be added to specific articles in the admin edit view. So far there is implementation to add the metabox to specific post types only.

Usage

Below are examples of how to create a segments metabox and how to get it inside a template. Other examples can be seen inside the examples directory.

Add meta box to edit view

The action "frojd_segments_metabox" can be called anywhere in the theme, most likely in functions.php. With specific parameters sent to the action hook, a metabox will be visible in the admin edit view of that type of article. This action should be called inside a function triggered by the "add_meta_boxes" action. Each segments metabox will show a list of all the available posts selected from the "selection" parameter. When an item is dragged to the selected list the options defined in the "options" parameter will be available in a small popup which opens when clicking the settings icon.

Example

add_action('add_meta_boxes', 'addMetaBoxesHook');
function addMetaBoxesHook() {
    $metaboxes = array();
    $metaboxes['segments_metabox'] = array(
        'title'             => __('Select my articles', get_translation_domain()), // defaults to "Select articles"
        'selection'         => array( // defaults to all posts, same parameters as in get_posts can be used here
            'post_type'         => array('page')
        ),
        'show_on'           => array(
            'post_types'        => array('page'), // defaults to page
            'valid_terms'       => array( // defaults to none, uses same parameters as has_term, term can be name/id/slug or array of them to check for, taxonomy is the name
                array('taxonomy' => 'term')
            ),
            'post_meta'         => array( // defaults to none, uses get_post_meta function to check, key is the field name and value is what to check for
                array('key' => 'value')
            )
        ),
        'options'           => array( // Options to be added to each item selected in the segment, can be used to e.g. implement grid layout or add an alternative title.
            'layout'            => array(
                'label'             => __('Grid layout', get_translation_domain()),
                'type'              => 'select', // Can be any text input field (text, number etc), select, checkbox or textarea
                'options'           => array( // Key and value of the options in select e.g. array('quarter' => '1/4')
                    'value' => 'name'
                )
            )
        )
    );
    do_action('frojd_segments_metabox', $metaboxes);
}

Retreive the segments from posts

The meta boxes and the posts selected can be retrieved in different ways. The filter "frojd_segments_get_segment" can accept two parameters (post id, and the meta box id) and will return the selected segment. The filter "frojd_segments_get_segments" can accept one parameter (post id), and will return the whole segments object with all the meta boxes for that post and including the selected posts in that. Otherwise th easiest way to implement the segments is to hook into the "the_post" function and add an attribute for the segments to the post object, seen in the example below. When this is done the segments object is available inside each loop where the global $post object is available.

Example

add_action('the_post', 'thePostHook');
function thePostHook($post) {
    // Adds a new value to the post object containing the post segments
    $segments = apply_filters('frojd_segments_get_segments', $post->ID);
    $post->segments = (object) $segments;
}

frojd/frojd-segments 适用场景与选型建议

frojd/frojd-segments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.03k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 frojd/frojd-segments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 frojd/frojd-segments 我们能提供哪些服务?
定制开发 / 二次开发

基于 frojd/frojd-segments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-07-03