It seems like stupid question. But, I can't figure it out :(.
I need to display button at home that goes to custom post_type's archive URL (archive-{post_type}.php). How do I do that?
|
It seems like stupid question. But, I can't figure it out :(. I need to display button at home that goes to custom post_type's archive URL (archive-{post_type}.php). How do I do that? |
|||
|
Hi @Silent: Turns out there is a function in WordPress 3.1 that does exactly what you want and it is named
Below is my prior answer before I discovered that WordPress did indeed have a function built-in for this use case. Prior Answer:Unless I overlooked something in the core source code for WordPress 3.1 I think you are looking for a function like
And here's the source code which you can place into your theme's
I was actually working on this exact logic over the weekend although I'm not yet 100% sure the order of the logic is generically correct across all use-cases that WordPress might see although it will probably work for any specific site. This is also a great thing to suggest be added to WordPress via trac which I think I will do later this evening. |
|||||||||||
|
|
when you register post type you can pass a string as slug with "has_archive" parameter and make sure you also set rewrite to either true or an array but not false and then your CPT archive URL would be http://www.YOURDOMAIN.com/has_archive_slug for example if you set in your register_post_type for example:
then your single url is: http://www.YOURDOMAIN.com/product/postName and your archive url is: http://www.YOURDOMAIN.com/products/ |
|||
|
|
yoursite.com/type-slugunless you explicitly set it to something else, eg.yoursite.com/some-other-url.. – t31os Mar 8 '11 at 23:30