Set a page as parent of a custom post type.
# April 17, 2013 at 9:20 am
I am currently redesigning my homepage and I want to build an image gallery with a permalink structure like the one on css-tricks (ex: **homepage/gallery/postname**).
I created a Custom Post Type in WordPress, to post each uploaded image on a seperate page. And I changed the rewrite slug of that post type, to get the permalinks right. But my Yoast Breadcrumbs still display something like: **homepage/postname** instead of: **homepage/gallery/postname**. After a lot of googling I found out, that I need to actually set the gallery page as a parent for the custom post type. WordPress doesn’t let you do that, but I found a [snippet](http://www.gravitationalfx.com/how-to-set-a-page-as-the-parent-of-a-wordpress-custom-post-type/), where one can specify a parent to the custom post type in wp’s admin area.
But isn’t there a easier solution to that problem? I know the post_id of my gallery page. And I don’t want to use any other parent page for my images, ever. So I don’t need any dropdown menus or text inputs. I just want that one custom post type to always have the gallery page as a parent.
I tried to fiddle around with the code, but I’m just too bad at PHP, to get it to work. So any help would be appreciated.
**EDIT**: After another 4 hours of tinkering… something starts to boggle my mind. Am I going down the right way, implementing the gallery like this or should I use another approach? I’m asking that, because after giving up on my initial problem and working on the gallery home page, I noticed, that it uses the **archive-custom post type.php** template and won’t accept any other template. That’s not the real problem though… I could just copy my markup from gallery.php to the archive-whatever.php, but Yoasts Breadcrumbs won’t label it as gallery but instead as the name of my custom post type… which is a little bit annoying. So… Am I doing it wrong?# April 20, 2013 at 7:14 am
@AlenAbdula thank you very much for going through so much trouble for my problem.
One thing keeps me wondering, though. Is this problem really that exotic? I see hundreds of sites on the web with that exact url structure and working breadcrumbs… someone must have come across that problem at least once.
How do you build your image galleries? Does everyone use a plugin or the WP Gallery shortcode? Please enlighten me ;)
You must be logged in to reply to this topic.