解決方案一:
我在這裏找到了解決方案:http://gabrieleromanato.name/wordpress-fix-the-404-error-on-custom-post-types/
這裏就是你需要做的就是它的工作(從上面的網站引用)的內容:
進入設置→永久鏈接,改變當前的結構:
/%類別%/%postname%保存更改。恢復您的原始永久鏈接 設置。保存更改。
二解決方案:
原來存在的WordPress 3.1,你想要做什麼的函數,它被命名爲get_post_type_archive_link();這裏是你怎麼稱呼它(假設命名爲「產品」自定義後類型):
<a href="<?php echo get_post_type_archive_link('product'); ?>">Products</a>
下面是我以前的答案之前,我發現的WordPress的確有內置的這種使用情況的功能。
此前答:
除非我忽視爲WordPress 3.1的核心源代碼,我認爲你正在尋找像get_archive_link()函數,你可以這樣調用的東西(假設命名的自定義職位類型「產品「):
<a href="<?php echo get_archive_link('product'); ?>">Products</a>
而這裏的源代碼,你可以放入你的主題function.php文件或一個插件,你可能會寫一個PHP文件:
if (!function_exists('get_archive_link')) {
function get_archive_link($post_type) {
global $wp_post_types;
$archive_link = false;
if (isset($wp_post_types[$post_type])) {
$wp_post_type = $wp_post_types[$post_type];
if ($wp_post_type->publicly_queryable)
if ($wp_post_type->has_archive && $wp_post_type->has_archive!==true)
$slug = $wp_post_type->has_archive;
else if (isset($wp_post_type->rewrite['slug']))
$slug = $wp_post_type->rewrite['slug'];
else
$slug = $post_type;
$archive_link = get_option('siteurl') . "/{$slug}/";
}
return apply_filters('archive_link', $archive_link, $post_type);
}
}
雖然我還沒有100%確定這個邏輯的順序在所有使用情況下一般都是正確的,但是WordPress可能會看到,儘管它可能適用於任何特定站點。
這也是一個偉大的事情,建議通過trac添加到WordPress,我認爲我會在今晚晚些時候做。
請出示你的代碼? –
我把這個放在我的主題索引上,嘗試瀏覽很多可能會返回的帖子和頁面,但只是false:var_dump(get_post_type_archive_link('video')); –
如果post_type不存在或post_type沒有存檔,它將返回false。 –