分类和自定义邮政类型的固定链接

时间:2013-08-31 作者:Cristiano Possa

这里有以下情况:

自定义帖子类型:“recipes”自定义帖子类型“recipes”的分类法:“receitas”分类法之一slug:“receitas whoopie”permalink结构必须为:

示例。com/receitas(显示自定义帖子类型“recipes”的所有帖子……如果需要,它可以是页面模板)
示例。com/receitas-whoopie(显示分类法“recipescat”->“receitas-whoopie-pie”下自定义帖子类型“recipes”的所有帖子)
示例。com/receitas-whoopie/post\\u name(在分类法“receitas”->“receitas-whoopie-pie”下显示单数帖子)

我尝试了许多通过过滤器实现这一点的方法,这是唯一有效的方法,访问/收据为whoopie派/post\\u名称

实际上,我有以下结构:


不管这个问题如何,我的函数:
示例。com/receitas(显示自定义帖子类型“recipes”-页面模板的所有帖子)
示例。com/receitas/receitas-whoopie(显示分类法“recipescat”->“receitas-whoopie-pie”下自定义帖子类型“recipes”的所有帖子)
示例。com/recipes/post\\u name(在分类法“receitas”->“receitas-whoopie-pie”下显示单数post)

add_action( \'init\', \'receitas_posttype\', 0 );
function receitas_posttype() {

    $labels = array(
        \'menu_name\'           => \'Receitas\',
        \'name\'                => \'Receitas\',
        \'singular_name\'       => \'Receita\',
        \'parent_item_colon\'   => \'\',
        \'all_items\'           => \'Todas as Receitas\',
        \'view_item\'           => \'Ver Receita\',
        \'add_new_item\'        => \'Adicionar Receita\',
        \'add_new\'             => \'Nova Receita\',
        \'edit_item\'           => \'Editar Receita\',
        \'update_item\'         => \'Atualizar Receita\',
        \'search_items\'        => \'Pesquisar Receita\',
        \'not_found\'           => \'Receita(s) não encontrada(s)\',
        \'not_found_in_trash\'  => \'Receita(s) não encontrada(s) no lixo\'
    );  

    $args = array(
        \'label\'               => \'recipes\',
        \'description\'         => \'Receitas\',
        \'labels\'              => $labels,
        \'supports\'            => array( \'title\', \'editor\', \'author\', \'thumbnail\' ),
        \'hierarchical\'        => true,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'show_in_admin_bar\'   => true,
        \'menu_position\'       => 100,
        \'menu_icon\'           => get_bloginfo(\'stylesheet_directory\').\'/images/receitas.png\',
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'capability_type\'     => \'post\',
    );

    register_post_type( \'recipes\', $args );

}

add_action( \'init\', \'receitascat\', 0 );
function receitascat()  {

    $labels = array(
        \'name\'                       => _x( \'Receitas\', \'Taxonomy General Name\', \'ickfd\' ),
        \'singular_name\'              => _x( \'Receita\', \'Taxonomy Singular Name\', \'ickfd\' ),
        \'menu_name\'                  => __( \'Categorias de Receita\', \'ickfd\' ),
        \'all_items\'                  => __( \'Todas as categorias\', \'ickfd\' ),
        \'parent_item\'                => __( \'Categoria pai\', \'ickfd\' ),
        \'parent_item_colon\'          => __( \'Categoria pai:\', \'ickfd\' ),
        \'new_item_name\'              => __( \'Nova categoria\', \'ickfd\' ),
        \'add_new_item\'               => __( \'Adicionar nova categoria\', \'ickfd\' ),
        \'edit_item\'                  => __( \'Editar categoria\', \'ickfd\' ),
        \'update_item\'                => __( \'Atualizar categoria\', \'ickfd\' ),
        \'separate_items_with_commas\' => __( \'Separe as categorias com vírgula\', \'ickfd\' ),
        \'search_items\'               => __( \'Pesquisar categorias\', \'ickfd\' ),
        \'add_or_remove_items\'        => __( \'Adicionar ou remover categorias\', \'ickfd\' ),
        \'choose_from_most_used\'      => __( \'Escolha as categorias mais usadas\', \'ickfd\' ),
    );
    $rewrite = array(
        \'slug\'                       => \'receitas\',
        \'with_front\'                 => true,
        \'hierarchical\'               => true,
    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => false,
        \'rewrite\'                    => $rewrite,
    );
    register_taxonomy( \'receitas\', \'recipes\', $args );

}
功能正常,但404页为单数页:

add_action( \'init\', \'receitas_posttype\', 0 );
function receitas_posttype() {

    $labels = array(
        \'menu_name\'           => \'Receitas\',
        \'name\'                => \'Receitas\',
        \'singular_name\'       => \'Receita\',
        \'parent_item_colon\'   => \'\',
        \'all_items\'           => \'Todas as Receitas\',
        \'view_item\'           => \'Ver Receita\',
        \'add_new_item\'        => \'Adicionar Receita\',
        \'add_new\'             => \'Nova Receita\',
        \'edit_item\'           => \'Editar Receita\',
        \'update_item\'         => \'Atualizar Receita\',
        \'search_items\'        => \'Pesquisar Receita\',
        \'not_found\'           => \'Receita(s) não encontrada(s)\',
        \'not_found_in_trash\'  => \'Receita(s) não encontrada(s) no lixo\'
    );  

    $args = array(
        \'label\'               => \'recipes\',
        \'description\'         => \'Receitas\',
        \'labels\'              => $labels,
        \'supports\'            => array( \'title\', \'editor\', \'author\', \'thumbnail\' ),
        \'hierarchical\'        => true,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'show_in_admin_bar\'   => true,
        \'menu_position\'       => 100,
        \'menu_icon\'           => get_bloginfo(\'stylesheet_directory\').\'/images/receitas.png\',
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'rewrite\'             => true,
        \'capability_type\'     => \'post\',
    );

    register_post_type( \'recipes\', $args );

}

// Ativação das categorias (taxonomias) do custom post type
add_action( \'init\', \'receitascat\', 0 );
function receitascat()  {

    $labels = array(
        \'name\'                       => _x( \'Receitas\', \'Taxonomy General Name\', \'ickfd\' ),
        \'singular_name\'              => _x( \'Receita\', \'Taxonomy Singular Name\', \'ickfd\' ),
        \'menu_name\'                  => __( \'Categorias de Receita\', \'ickfd\' ),
        \'all_items\'                  => __( \'Todas as categorias\', \'ickfd\' ),
        \'parent_item\'                => __( \'Categoria pai\', \'ickfd\' ),
        \'parent_item_colon\'          => __( \'Categoria pai:\', \'ickfd\' ),
        \'new_item_name\'              => __( \'Nova categoria\', \'ickfd\' ),
        \'add_new_item\'               => __( \'Adicionar nova categoria\', \'ickfd\' ),
        \'edit_item\'                  => __( \'Editar categoria\', \'ickfd\' ),
        \'update_item\'                => __( \'Atualizar categoria\', \'ickfd\' ),
        \'separate_items_with_commas\' => __( \'Separe as categorias com vírgula\', \'ickfd\' ),
        \'search_items\'               => __( \'Pesquisar categorias\', \'ickfd\' ),
        \'add_or_remove_items\'        => __( \'Adicionar ou remover categorias\', \'ickfd\' ),
        \'choose_from_most_used\'      => __( \'Escolha as categorias mais usadas\', \'ickfd\' ),
    );

    $rewrite = array(
            \'slug\'                       => \'\',
            \'with_front\'                 => false,
            \'hierarchical\'               => true,
        );

    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => false,
        \'rewrite\'                    => $rewrite,
    );
    register_taxonomy( \'receitas\', \'recipes\', $args );

}

function filter_post_type_link($link, $post)
{
    if ($post->post_type != \'recipes\')
        return $link;

    if ($cats = get_the_terms($post->ID, \'receitas\'))
        $link = str_replace(\'recipes\', array_pop($cats)->slug, $link);
    return $link;
}
add_filter(\'post_type_link\', \'filter_post_type_link\', 10, 2);
提前谢谢。对不起,我的英语不好(

1 个回复
SO网友:Raank

VocêjáusouCustom post type permalinks?

你用过吗custom post type permalink?

例如:示例。组织/职位类型/分类法\\u名称/术语\\u slug

结束

相关推荐

Grouped custom taxonomy query

我已经创建了自定义帖子类型:图像库自定义分类:媒体类别(在媒体类别下):categoria uno和categoria due我需要打印按类别分组的记录,例如:uno分类记录1,记录2,记录3,分类到期记录1记录2记录3任何人都可以帮助我进行此查询吗?提前谢谢你