【问题标题】:Is this possible in Wordpress这在 Wordpress 中是否可能
【发布时间】:2013-03-10 17:51:27
【问题描述】:

我正在尝试做一些我不确定是否可行并且需要一个大方向的事情。我有一个 Wordpress 3.31 多站点设置。我设置了几个自定义角色。学生、教师 1、教师 2、教师 3、家人和朋友。

我还设置了几种自定义帖子类型。我关心的是教师自定义帖子类型。

在不久的将来,我们将不得不向这个系统添加大约 3000 个博客。我希望自定义帖子类型的名称成为该博客教师角色的人的姓名 - 自动。每个博客最多可以有三位教师。

所以我想以某种方式查询 wp_usermeta 的教师角色,然后显示教师的姓名。在自定义帖子设置中(如下)它必须循环最多三次,因为学生可能有几位老师。任何人都知道这是否可能和大方向?

I.E.

register_post_type( 'journal_teacher',
    array(
        'labels' => array(
            'name' => __(query-here-for-teacher-role) ),...

【问题讨论】:

  • 你的问题如果在标题中会更成功。例如:如何制作动态命名的 Wordpress 自定义帖子类型?此外,Wordpress 堆栈交换可能与您的兴趣相关。 wordpress.stackexchange.com

标签: wordpress


【解决方案1】:

如果您正在考虑将 Wordpress 转变为 LMS 系统,我强烈建议您使用课件,http://coursewa.re/。对你有很大帮助。

【讨论】:

    【解决方案2】:

    我有一个自定义帖子类型,包括我使用的。大致包括这样的内容:

    您可能会为 $types 数组创建一些东西来帮助您完成所需的工作。

    <?php
    // ADDING CUSTOM POST TYPE
    add_action('init', 'all_custom_post_types');
    
    function all_custom_post_types() {
    
        $types = array(
    
            // Student
            array('the_type' => 'students',
              'single' => 'Student',
              'plural' => 'Students',
              'hierarchical' => true,
              'support' => array('title','editor','thumbnail','custom-fields'),
              'taxonomy' => array('') ),
    
           // Teacher1
           array('the_type' => 'teacher1',
              'single' => 'Teacher1',
              'plural' => 'Teachers1',
              'hierarchical' => true,
              'support' => array('title','editor','thumbnail','custom-fields'),
              'taxonomy' => array('') ),
    
          // Teacher2
                    array('the_type' => 'teacher2',
                      'single' => 'Teacher2',
                      'plural' => 'Teachers2',
                      'hierarchical' => true,
                      'support' => array('title','editor','thumbnail','custom-fields'),
                      'taxonomy' => array('') ),
    
                    // Teacher3
                    array('the_type' => 'teacher3',
                      'single' => 'Teacher3',
                      'plural' => 'Teachers3',
                      'hierarchical' => true,
                      'support' => array('title','editor','thumbnail','custom-fields'),
                      'taxonomy' => array('') ),
    
                    // Family and Friends - not sure if this is 2 or 1 category - but you get the idea by now.
                    array('the_type' => 'family-and-friends',
                      'single' => 'Family and Friends',
                      'plural' => 'Family and Friends',
                      'hierarchical' => true,
                      'support' => array('title','editor','thumbnail','custom-fields'),
                      'taxonomy' => array('') )
    
            );
    
        foreach ($types as $type) {
    
            $the_type = $type['the_type'];
          $single = $type['single'];
          $plural = $type['plural'];
    
            $labels = array(
            'name' => _x($plural, 'post type general name'),
            'singular_name' => _x($single, 'post type singular name'),
            'add_new' => _x('Add New', $single),
            'add_new_item' => __('Add New '. $single),
            'edit_item' => __('Edit '.$single),
            'new_item' => __('New '.$single),
            'view_item' => __('View '.$single),
            'search_items' => __('Search '.$plural),
            'not_found' =>  __('No '.$plural.' found'),
            'not_found_in_trash' => __('No '.$plural.' found in Trash'),
            'parent_item_colon' => ''
          );
    
          $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true, // $rewriter,
            'capability_type' => 'post',
            'hierarchical' => $type['hierarchical'],
            'menu_position' => 5,
            'supports' => $type['support']
          );
    
          register_post_type($the_type, $args);
    
        }
    
    }
    
    ?>
    

    我已经为您修改了 $types 数组 - 如果您需要调整它,希望您了解如何从中进行调整。如果没有,我可能需要更多信息。

    【讨论】:

    • 谢谢...如果我使用函数 get_users/get_user_meta 在 $types 中“获取”与博客相关联的教师 ID,那么我可以在标签数组中使用该变量来自定义帖子类型教师吗?感谢您提供任何额外的方向...
    • 这绝对让我朝着正确的方向前进 - 现在我只需要通过博客 ID 和教师角色中的老师的名字来做这件事 - 感谢您的领先;-) 不知道如何这样做 - 但会到处玩,看看我能得到什么 - 非常感谢你的帮助!
    • @Mike: user10660 tried to amend your answer -- 有些内容看起来很有用,但我对这方面的了解不如你。随心所欲地使用它。 (我什么都不做。)
    猜你喜欢
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多