0

All, I have a post that works fine with a permalink setup. However, I also have a page called gallery. What I would each post can have a page. So for example I have a post named business-name so my URL would look like this:

http://website.com/business-name

I then want to click on a gallery link for this and that is a page I have created in wordpress. So I was looking to have a URL structure like this:

http://website.com/business-name/gallery

If I change my permalink structure to something like this: /%postname%/%page%/

Then I go to the second link in my question it overwrites the URL to this: http://website.com/gallery

Is something like this possible with a post and then a page?

Thanks

  • I would look at using add_rewrite_endpoint like in this answer. – Milo Oct 23 '14 at 17:01
  • @Milo I think this looks helpful. This answer specifies a certain template though. My code is actually in a Page within Wordpress and uses a default template that I assign in the dashboard. Is there a way to call the gallery page instead of a template? – user1048676 Oct 23 '14 at 19:30
  • @Milo I would then like to load the gallery page but since it started with a post I could declare the $post as global variable inside the page and use the $post->ID to only select certain images for the gallery because I have a custom $wpdb query on this page to filter by that ID. I hope this helps and gives a little more clarity. Thanks! – user1048676 Oct 24 '14 at 3:30
  • The code is in the actual page within the admin instead of on a template. I know I could create a template but it wasn't working correctly because it had a bunch of short codes that don't recognize the closing tag in do_shortcode and don't want to have to rewrite that code. – user1048676 Oct 24 '14 at 3:39
0

Since posts are not hierarchical and pages are - even if you're linking to a page from a post, there's nothing telling WordPress that they're related. So the urls you're going to get will be www.site.com/page or www.site.com/post.

If you'd like to relate them, you can either use Pages for both and take advantage of the hierarchy Wordpress provides (see link below). Or you can have a custom post type and set the hierarchy parameter to true. You can also set your custom post type to behave like a page if that's the reason why you're trying to use post > page.

You may have other options, but I'm not sure what the circumstances are for your site, and why you'd be using a post and a page as two separate entities and trying to relate them. Perhaps if you can explain why you're trying to build it as post > page, I can provide more options for you.

Also don't forget about categories, if you're using a post simply to have the url be www.site.com/something/gallery, you can also take advantage of categories.

Hope that helps!

  • I don't know if the hierarchy would work because a page would be associated with multiple posts. So I would have a lot of different posts and for each business I would like to have the same gallery page because I have code in there to select certain images based on post id. I wouldn't make the gallery page have a parent because each post would be a parent of that page. Does that make sense? – user1048676 Oct 23 '14 at 16:55
  • Oh I see, so then you'd have Business A and Business B, and Gallery Page might be a child of both posts? This plugin can help you relate custom post types, so instead of having post > page, you'd have custom post type > custom post type. wp-types.com/documentation/user-guides/… I can see what I find on doing this manually if you don't want the plugin route. – RachieVee Oct 23 '14 at 17:03
  • Also try this older question about relating two custom post types: wordpress.stackexchange.com/questions/16292/… – RachieVee Oct 23 '14 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.