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

4
  • I would look at using add_rewrite_endpoint like in this answer.
    – Milo
    Commented Oct 23, 2014 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? Commented Oct 23, 2014 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! Commented Oct 24, 2014 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. Commented Oct 24, 2014 at 3:39

1 Answer 1

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!

3
  • 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? Commented Oct 23, 2014 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
    Commented Oct 23, 2014 at 17:03
  • Also try this older question about relating two custom post types: wordpress.stackexchange.com/questions/16292/…
    – RachieVee
    Commented Oct 23, 2014 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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