2012-04-25 104 views
0

我今天刚第一次使用自定义帖子类型,所以请原谅我的无知。WordPress的:你可以分配常规职位类别自定义职位类型?

我正在使用由插件预定义的自定义帖子类型。看起来几乎每个Event Calendar插件都使用自定义帖子类型来设置“Events”帖子类型。

我想知道是否有一种方法来使用我分配给我的常规帖子的正常类别,以分配给自定义事件帖子。

例如,我有地区类别,例如我一直用于常规帖子的“东南”,但我也希望能够将此类别分配给事件帖子,以便当人们查看“东南“类别档案,他们可以看到与该类别相关的常规帖子和事件帖子。

这可能吗?

感谢所有帮助提前

+0

是的,它是可能的,但取决于你使用的是定义你的职位类型的插件。那么这个插件是什么? – soju 2012-04-25 07:05:57

+0

我还没有确定事件插件,但我可能会使用** All-in-One事件日历**。 – danapaige 2012-04-25 19:45:45

回答

0

我使用的代码和指令在这里: http://wp.miragearts.com/allinone-event-calendar-events-blog-home-categories-tags/

我发现这个代码添加到了functions.php,如果我创建了两个类别(一个用于常规pos ts和一个用于事件定制的帖子),它们的名称和slu exact相同,然后它与拥有一个类别基本相同。

我认为这可能会使我的网站变慢一点,但现在确定它是否会引起问题还为时尚早。

下面是对的functions.php代码的副本:

// Add this to your theme's functions.php 
function edit_my_query($query) { 
    // Modify category and tag listings to include ai1ec events and all uses of the same term 
    // across event and post taxonomies 
    // ie live-music or arts whether they are event or post categories 
    // also include ai1ec events in blog home and feeds 
    if ((is_home() || is_feed() || is_category() || is_tag()) 
      && empty($query->query_vars['suppress_filters'])) { 
    // The 'suppress_filters' test above keeps your menus from breaking 
    $post_type = get_query_var('post_type'); 
    if($post_type && $post_type[0] != 'post') { 
     $post_type = $post_type; 
    } else { 
     $post_type = array('post','ai1ec_event'); // add custom post types here 
    } 
    $query->set('post_type',$post_type); 
    if (is_category() || is_tag()) { 
    // Add custom taxonomies to category and tag pages 
    if (is_category()) { 
     $taxonomy1 = 'category'; 
     $taxonomy2 = 'events_categories'; 
     } 
     if (is_tag()){ 
     $taxonomy1 = 'post_tag'; 
     $taxonomy2 = 'events_tags'; 
     } 
     $queried_object = $query->get_queried_object(); 
     $slug = $queried_object->slug; 
     $query->set('tax_query', array(
     'relation' => 'OR', 
     array(
      'taxonomy' => $taxonomy1, 'field' => 'slug', 'terms' => $slug 
     ), 
     array(
      'taxonomy' => $taxonomy2, 'field' => 'slug', 'terms' => $slug 
     ) 
    )); 
    } 
    } 
} 
add_action('pre_get_posts', 'edit_my_query'); 
0

你想使用WordPress的功能register_taxonomy_for_object_type()把下面的到你的主题的的functions.php文件:

function add_categories_to_events() { 
    register_taxonomy_for_object_type('post_tag', 'event'); 
} 
add_action('init', 'add_categories_to_events'); 
+0

我试过了,得到这个错误:**警告:call_user_func_array()[function.call-user-func-array]:第一个参数预计是一个有效的回调,'add_category_to_events'在/ homepages/0/d328057274/htdocs/cfsa-test/wp-includes/plugin.php 405行** 我也尝试过使用这个功能,但自从使用All-in-One事件日历以来,将'events'更改为'ai1ec-events'。相同的错误消息。 我在Wordpress.org上发现了这篇文章,我将尝试遵循以下指示:http://wordpress.org/support/topic/plugin-all-in-one-event-calendar-how-add-events-入户饲料类别,tagsh – danapaige 2012-04-25 20:07:18

1

简单:

add_action('init', 'myfuncxx'); function myfuncxx() { 
    register_taxonomy_for_object_type('category', 'custom_postttt_typee'); 
} 
相关问题