【问题标题】:how to insert yoast main category in advanced custom fields?如何在高级自定义字段中插入 yoast 主类别?
【发布时间】:2019-08-06 15:04:55
【问题描述】:

我想在高级自定义字段中构建块时使用 yoast 的主类别

        //Primary Yoast Category
        $primaryCat = new WPSEO_Primary_Term('category', get_the_ID());
        $primaryCat = $primaryCat->get_primary_term();


        $catPrimaryName = get_cat_name($primaryCat);
        $catPrimaryLink = get_category_link($primaryCat);
        $context['catPrimaryLink'] = $catPrimaryLink;
        $context['catPrimaryName'] = $catPrimaryName;

// ----------

【问题讨论】:

    标签: php wordpress categories advanced-custom-fields yoast


    【解决方案1】:
            if (is_array($modules['categories']))
            add_filter('block_categories', function ($categories, $post) use ($modules) {
                $module_categories = [];
                foreach ($modules['categories'] as $module_category)
                    $module_categories[] = [
                        'slug' => $this->block_category_slug . '_' . $module_category,
                        'title' => $this->block_category_title . ' - ' . $module_category
                    ];
    
                return array_merge($module_categories, $categories);
            }, 10, 2);
    
        // add our blocks & fields
        foreach ($modules['modules'] as $block) {
            acf_register_block(array(
                'name' => $block['name'],
                'title' => __($block['title']),
                'description' => __($block['description']),
                'render_callback' => [$this, 'my_acf_block_render_callback'],
                'category' => $this->block_category_slug . '_' . $block['category'],
                'icon' => 'layout',
                'align' => 'wide',
                'keywords' => array_merge($this->default_keywords, isset($block['keywords']) && is_array($block['keywords']) ? $block['keywords'] : []),
            ));
    

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 1970-01-01
      • 2015-12-30
      • 2019-08-17
      • 2015-07-31
      • 1970-01-01
      • 2017-08-28
      • 2020-07-08
      • 2017-05-01
      相关资源
      最近更新 更多