自定义帖子类型档案页面空白

时间:2017-10-29 作者:Yamona

我用slug创建了一个CPTplist 通过我制作的cutom插件。

在我的本地主机中,存档工作,但在live server中,它返回空白页。

以下是“包含”存档页代码

/**
 * Add Price List archive template
 * @since    1.0.0
*/
add_filter( \'archive_template\', \'get_plist_archive_template\' ) ;
function get_plist_archive_template( $archive_template ) {
     global $post;

     if ( is_post_type_archive ( \'plist\' ) ) {
          $archive_template = dirname( __FILE__ ) . \'\\partials\\archive-plist.php\';
     }
     return $archive_template;
}
链接:http://cratetimer.com/plist/

这也可能有助于:

/**
 * Register Custom Post Type Price List
 * @since    1.0.0
*/
if ( ! function_exists(\'price_item_post_type\') ) {
    add_action( \'init\', \'price_item_post_type\', 0 );
    // Register Custom Post Type
    function price_item_post_type() {

        $labels = array(
            \'name\'                  => _x( \'Price Lists\', \'Post Type General Name\', \'plist\' ),
            \'singular_name\'         => _x( \'Price List\', \'Post Type Singular Name\', \'plist\' ),
            \'menu_name\'             => __( \'Price List\', \'plist\' ),
            \'name_admin_bar\'        => __( \'Price List\', \'plist\' ),
            \'archives\'              => __( \'Price List Archives\', \'plist\' ),
            \'attributes\'            => __( \'Price List Attributes\', \'plist\' ),
            \'parent_item_colon\'     => __( \'Parent Price List:\', \'plist\' ),
            \'all_items\'             => __( \'All Price Lists\', \'plist\' ),
            \'add_new_item\'          => __( \'Add New Price List\', \'plist\' ),
            \'add_new\'               => __( \'Add New\', \'plist\' ),
            \'new_item\'              => __( \'New Price List\', \'plist\' ),
            \'edit_item\'             => __( \'Edit Price List\', \'plist\' ),
            \'update_item\'           => __( \'Update Price List\', \'plist\' ),
            \'view_item\'             => __( \'View Price List\', \'plist\' ),
            \'view_items\'            => __( \'View Price Lists\', \'plist\' ),
            \'search_items\'          => __( \'Search Price List\', \'plist\' ),
            \'not_found\'             => __( \'Not found\', \'plist\' ),
            \'not_found_in_trash\'    => __( \'Not found in Trash\', \'plist\' ),
            \'featured_image\'        => __( \'Featured Image\', \'plist\' ),
            \'set_featured_image\'    => __( \'Set featured image\', \'plist\' ),
            \'remove_featured_image\' => __( \'Remove featured image\', \'plist\' ),
            \'use_featured_image\'    => __( \'Use as featured image\', \'plist\' ),
            \'insert_into_item\'      => __( \'Insert into Price List\', \'plist\' ),
            \'uploaded_to_this_item\' => __( \'Uploaded to this Price List\', \'plist\' ),
            \'items_list\'            => __( \'Price Lists\', \'plist\' ),
            \'items_list_navigation\' => __( \'Price Lists navigation\', \'plist\' ),
            \'filter_items_list\'     => __( \'Filter Price Lists\', \'plist\' ),
        );
        $args = array(
            \'label\'                 => __( \'Price List\', \'plist\' ),
            \'description\'           => __( \'Price list item for market\', \'plist\' ),
            \'labels\'                => $labels,
            \'supports\'              => array( ),
            \'hierarchical\'          => false,
            \'public\'                => true,
            \'show_ui\'               => true,
            \'show_in_menu\'          => true,
            \'menu_position\'         => 20,
            \'menu_icon\'             => \'dashicons-tag\',
            \'show_in_admin_bar\'     => true,
            \'show_in_nav_menus\'     => true,
            \'can_export\'            => true,
            \'has_archive\'           => true,        
            \'exclude_from_search\'   => true,
            \'publicly_queryable\'    => true,
            \'capability_type\'       => \'page\',
        );
        register_post_type( \'plist\', $args );

    }

}
我尝试了flush\\u rewrite\\u rules(),但没有成功。

2 个回复
SO网友:ninjacolin

你必须告诉WP那个档案。php应该应用于您的自定义帖子类型以及其他默认设置。您可以使用pre_get_posts filter 要做到这一点,在使用之前一定要仔细研究,因为使用这个过滤器有对有错。

例如,尝试:

function add_custom_post_type_to_archiving( $query ) {
    $query->set( \'post_type\', array(
     \'post\', \'custom_post_type_name1\',\'custom_post_type_name2\'
        ));
    return $query;
}
add_filter( \'pre_get_posts\', \'add_custom_post_type_to_archiving\' );

SO网友:Justin Waulters

由于它在本地机器上工作,而不是在服务器上,我怀疑它与环境有关。这让我怀疑:

$archive_template = dirname( __FILE__ ) . \'\\partials\\archive-plist.php\';
如果在标准灯堆栈上运行此操作,则可能应该使用正斜杠(/) 而不是反斜杠(\\).

此外,还有一种可能性dirname() 调用返回的路径末尾有一个斜杠,这意味着该路径中有一个双斜杠(可能是/\\).

我建议尝试改变你的斜线的方向,然后改变dirname()plugin_dir_path(). 你会注意到的plugin_dir_path() 使用名为trailingslashit() 如果还没有斜杠,它会附加一个尾随斜杠。这意味着您应该删除路径中的第一条斜线。

总的来说,它看起来是这样的:

$archive_template = plugin_dir_path( __FILE__ ) . \'partials/archive-plist.php\';

结束

相关推荐

Custom archives function

我正在为我的教会网站建立一个自定义档案页面。在我的档案页上,我想把上周的布道放在一个特殊的盒子里,然后是未来的布道,最后是布道档案。我希望将来的布道和布道档案用标题隔开。。。i、 未来的布道布道档案布道档案。。。我的问题是,当我用分页功能点击按钮转到旧的布道帖子时,它会在我所在的每个归档页面上显示当前和未来的布道!如何使当前和未来的布道仅显示在第1页上,而不在单击查看旧帖子时显示?以下是我的功能:// Create the loop for the sermons page function se

自定义帖子类型档案页面空白 - 小码农CODE - 行之有效找到问题解决它

自定义帖子类型档案页面空白

时间:2017-10-29 作者:Yamona

我用slug创建了一个CPTplist 通过我制作的cutom插件。

在我的本地主机中,存档工作,但在live server中,它返回空白页。

以下是“包含”存档页代码

/**
 * Add Price List archive template
 * @since    1.0.0
*/
add_filter( \'archive_template\', \'get_plist_archive_template\' ) ;
function get_plist_archive_template( $archive_template ) {
     global $post;

     if ( is_post_type_archive ( \'plist\' ) ) {
          $archive_template = dirname( __FILE__ ) . \'\\partials\\archive-plist.php\';
     }
     return $archive_template;
}
链接:http://cratetimer.com/plist/

这也可能有助于:

/**
 * Register Custom Post Type Price List
 * @since    1.0.0
*/
if ( ! function_exists(\'price_item_post_type\') ) {
    add_action( \'init\', \'price_item_post_type\', 0 );
    // Register Custom Post Type
    function price_item_post_type() {

        $labels = array(
            \'name\'                  => _x( \'Price Lists\', \'Post Type General Name\', \'plist\' ),
            \'singular_name\'         => _x( \'Price List\', \'Post Type Singular Name\', \'plist\' ),
            \'menu_name\'             => __( \'Price List\', \'plist\' ),
            \'name_admin_bar\'        => __( \'Price List\', \'plist\' ),
            \'archives\'              => __( \'Price List Archives\', \'plist\' ),
            \'attributes\'            => __( \'Price List Attributes\', \'plist\' ),
            \'parent_item_colon\'     => __( \'Parent Price List:\', \'plist\' ),
            \'all_items\'             => __( \'All Price Lists\', \'plist\' ),
            \'add_new_item\'          => __( \'Add New Price List\', \'plist\' ),
            \'add_new\'               => __( \'Add New\', \'plist\' ),
            \'new_item\'              => __( \'New Price List\', \'plist\' ),
            \'edit_item\'             => __( \'Edit Price List\', \'plist\' ),
            \'update_item\'           => __( \'Update Price List\', \'plist\' ),
            \'view_item\'             => __( \'View Price List\', \'plist\' ),
            \'view_items\'            => __( \'View Price Lists\', \'plist\' ),
            \'search_items\'          => __( \'Search Price List\', \'plist\' ),
            \'not_found\'             => __( \'Not found\', \'plist\' ),
            \'not_found_in_trash\'    => __( \'Not found in Trash\', \'plist\' ),
            \'featured_image\'        => __( \'Featured Image\', \'plist\' ),
            \'set_featured_image\'    => __( \'Set featured image\', \'plist\' ),
            \'remove_featured_image\' => __( \'Remove featured image\', \'plist\' ),
            \'use_featured_image\'    => __( \'Use as featured image\', \'plist\' ),
            \'insert_into_item\'      => __( \'Insert into Price List\', \'plist\' ),
            \'uploaded_to_this_item\' => __( \'Uploaded to this Price List\', \'plist\' ),
            \'items_list\'            => __( \'Price Lists\', \'plist\' ),
            \'items_list_navigation\' => __( \'Price Lists navigation\', \'plist\' ),
            \'filter_items_list\'     => __( \'Filter Price Lists\', \'plist\' ),
        );
        $args = array(
            \'label\'                 => __( \'Price List\', \'plist\' ),
            \'description\'           => __( \'Price list item for market\', \'plist\' ),
            \'labels\'                => $labels,
            \'supports\'              => array( ),
            \'hierarchical\'          => false,
            \'public\'                => true,
            \'show_ui\'               => true,
            \'show_in_menu\'          => true,
            \'menu_position\'         => 20,
            \'menu_icon\'             => \'dashicons-tag\',
            \'show_in_admin_bar\'     => true,
            \'show_in_nav_menus\'     => true,
            \'can_export\'            => true,
            \'has_archive\'           => true,        
            \'exclude_from_search\'   => true,
            \'publicly_queryable\'    => true,
            \'capability_type\'       => \'page\',
        );
        register_post_type( \'plist\', $args );

    }

}
我尝试了flush\\u rewrite\\u rules(),但没有成功。

2 个回复
SO网友:ninjacolin

你必须告诉WP那个档案。php应该应用于您的自定义帖子类型以及其他默认设置。您可以使用pre_get_posts filter 要做到这一点,在使用之前一定要仔细研究,因为使用这个过滤器有对有错。

例如,尝试:

function add_custom_post_type_to_archiving( $query ) {
    $query->set( \'post_type\', array(
     \'post\', \'custom_post_type_name1\',\'custom_post_type_name2\'
        ));
    return $query;
}
add_filter( \'pre_get_posts\', \'add_custom_post_type_to_archiving\' );

SO网友:Justin Waulters

由于它在本地机器上工作,而不是在服务器上,我怀疑它与环境有关。这让我怀疑:

$archive_template = dirname( __FILE__ ) . \'\\partials\\archive-plist.php\';
如果在标准灯堆栈上运行此操作,则可能应该使用正斜杠(/) 而不是反斜杠(\\).

此外,还有一种可能性dirname() 调用返回的路径末尾有一个斜杠,这意味着该路径中有一个双斜杠(可能是/\\).

我建议尝试改变你的斜线的方向,然后改变dirname()plugin_dir_path(). 你会注意到的plugin_dir_path() 使用名为trailingslashit() 如果还没有斜杠,它会附加一个尾随斜杠。这意味着您应该删除路径中的第一条斜线。

总的来说,它看起来是这样的:

$archive_template = plugin_dir_path( __FILE__ ) . \'partials/archive-plist.php\';

相关推荐

permalinks issue and archives

我对运行在WP 3.3上的一个站点有一个问题,当我们通过“/%post\\u id%/%postname%/”使永久链接成为任何内容时,归档页面会断开并变成404。经过一些研究,我明白了为什么从性能的角度来看,这不是一个好的做法,所以我尝试了建议的备选方案:“/%year%/%postname%/”和“/%post\\u id%/%postname%/”这两个建议都有效,只是只有使用post\\u id的建议,归档URL才会变成“/date/2012/11/”,并被找到。根据permalink的任何其他建