I can't seem to get this to work how I want it to, but here's basically what I want to do:
I have a page called "album". This has all of the photo albums on that page. Then you click an album to go to the photo gallery for that album. I have a custom template for this page set, so all of the different albums will use this template. From here, I want to be able to click on an image and take it to the single image view. Because the photo gallery page is a custom post type, when I go to the single image, I have a file called "single-gallery.php" which then should display and then gather the image data to display it.
This is all working, however I want to keep the URL a certain way throughout this. I have almost got it how I want it, however the issue I am having is that I need to rewrite the URL in the gallery custom post type and use a custom field value in the URL to indicate which album this is.
For registering my "gallery" custom post type, I have this to rewrite my URL:
'rewrite' => array('slug'=>'album/%albumName%','with_front' => true),
Then in the gallery page template I use php to replace %albumName% with the current album.
$photoPermalink = str_replace('%albumName%', $albumName, $photoPermalink);
The problem is that I guess WordPress has to index the permalinks, and it's indexing the %albumName%, so when I change it with PHP it gets broken.
Is there a way to do this?