简体   繁体   English

删除自定义帖子类型的URL结构

[英]Remove URL structure for custom post type

I would like to know if its possible to remove URL structure for a custom post type. 我想知道是否可以删除自定义帖子类型的URL结构。 For example, I have 2 custom post types: portfolio and slider. 例如,我有2种自定义帖子类型:投资组合和滑块。

I want to keep URL structure for portfolio post type like this: mysite.com/portfolio/item-1 etc. 我想保留投资组合帖子类型的URL结构,如:mysite.com/portfolio/item-1等。

But I dont want URL structure for slider posts, since the slider will only be shown on the home page and I dont want visitors to be able to access it by going to mysite.com/slider/slide-1 for example. 但我不想要滑块帖子的URL结构,因为滑块只会显示在主页上,我不希望访问者能够通过访问mysite.com/slider/slide-1来访问它。 Is it possible? 可能吗?

Thanks in advance :) 提前致谢 :)

Wordpress forums post: http://wordpress.org/support/topic/no-url-structure-for-custom-post-type-1?replies=1 Wordpress论坛帖子: http ://wordpress.org/support/topic/no-url-structure-for-custom-post-type-1 ?replies = 1

When you do register new custom post you're using register post type , right? 当您注册新的自定义帖子时,您正在使用register post type ,对吧? There are options 有选择

'rewrite'            => false,
'query_var'          => false,
'publicly_queryable' => false,
'public'             => false

After WordPress documentation: WordPress文档之后:

rewrite Triggers the handling of rewrites for this post type. rewrite触发此帖子类型的重写处理。 To prevent rewrites, set to false. 要防止重写,请设置为false。

query_var 'false' - Disables query_var key use. query_var ' - 禁用query_var密钥使用。 A post type cannot be loaded at /?{query_var}={single_post_slug} 无法在/?{query_var} = {single_post_slug}加载帖子类型

publicly_queryable Whether queries can be performed on the front end as part of parse_request(). publicly_queryable是否可以作为parse_request()的一部分在前端执行查询。

public 'false' - Post type is not intended to be used publicly and should generally be unavailable in wp-admin and on the front end unless explicitly planned for elsewhere. public “假” -邮政型不打算公开使用,一般应在可湿性粉剂管理员和前端除非明确计划在其他地方无法使用。

Now go to Permalinks Settings and without changing anything - save change. 现在转到固定链接设置而不更改任何内容 - 保存更改。 It will rebuild your "routing". 它将重建您的“路由”。

Such setup will disable your custom post from frontend. 此类设置将禁用前端的自定义帖子。

I had similar problem, in my case I had custom post type like this: 我有类似的问题,在我的情况下我有这样的自定义帖子类型:

mypage.com/type

and inside I've got a lot of posts, so of course this generated for me pages looks like: 在里面我有很多帖子,所以当然这为我生成的页面看起来像:

mypage.com/type/page1
mypage.com/type/page2
...

BUT, I knew that in the future I'll make websites there, so simple I made a redirection inside this custom post type webpages. 但是,我知道将来我会在那里制作网站,这么简单,我在这个自定义的帖子类型网页中进行了重定向。 So inside single-type.php I added: 所以在single-type.php里面我添加了:

<script>
    window.location.href='www.mypage.com/404';
</script>

So this simply redirect people to 404 page. 所以这只是将人们重定向到404页面。 Few weeks later, when I wanted to turn on these pages, I just deleted this code. 几个星期后,当我想打开这些页面时,我刚刚删除了这段代码。

This is just a temporary workaround, but I hope it could help someone. 这只是一个临时的解决方法,但我希望它可以帮助某人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为自定义帖子类型类别创建自定义URL结构? - How to create custom url structure for custom post type categories? 为单个自定义帖子类型页面使用辅助模板和 URL 结构 - Using Secondary Template and URL Structure for Single Custom Post Type Pages 从自定义帖子类型的网址中删除父类别:产品-wordpress - Remove Parent Categories from URL of custom post type: product - wordpress 如何从WordPress的自定义帖子类型的URL中删除博客? - how to remove blog from custom post type url in wordpress? 在Wordpress中使用自定义分类法和自定义帖子类型的术语设置类似于商店的url结构 - Setting up a store-like url structure in Wordpress with custom taxonomies and terms for a custom post type 自定义帖子类型固定链接删除 - Custom post type permalink remove WordPress 自定义帖子类型的永久链接结构 - WordPress Permalink Structure for Custom Post Type 如何在WordPress中实现URL结构,例如“网站名称/存档页面/类别(或自定义分类法/自定义帖子类型)”? - How to achieve URL structure like “website-name/archive-page/category(or custom taxonomy)/custom-post-type” in WordPress? 防止WordPress删除添加在我的网址中的变量(自定义帖子类型) - Prevent WordPress to remove my variables added in my url (custom post type) 如何删除 URL 中的 /blog/ slug in a WordPress custom type post - How do I remove /blog/ slug in URL in a WordPress custom type post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM