Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following basic page setup:

  • xxx.net/ -> static homepage
  • xxx.net/blog/ -> blog page with loop showing all posts
  • xxx.net/gallery/ -> gallery page with loop only showing posts that are categorized as "gallery"
  • xxx.net/extra/ -> another page with loop only showing posts that are categorized as "extra"

The two special categories "gallery" and "extra" are used to filter certain posts and display them in a different way:

On /gallery, only posts of category "gallery" are shown (actually there custom excerpts rather than their standard content); the equivalent holds true for "extra".

So far that's all clear to me, however depending on whether a post is shown as part of the blog loop or the other loops, different post templates are used: if a post is called via xxx.net/gallery/post-name, the gallery template is used, if called via xxx.net/blog/post-name, the standard template is used.

How can I do this? I somehow think the answer is simple but I just don't see it right now! Would it make sense to use a new, custom taxonomy rather than categories to distinguish the "special" posts? The main question regarding permalinks remains the same however.

Addition:

I guess I could create a single.php with the following switcher:

if ( URL INCLUDES /GALLERY/ ) {include (TEMPLATEPATH . '/single-gallery.php');}
else if ( URL INCLUDES /EXTRA/ ) { include (TEMPLATEPATH . '/single-extra.php');}
else { include (TEMPLATEPATH . '/single-blog.php'); }

However I think a rewrite rule or similar would be the better approach. What is your take on the topic?

Second Addition:

To further explain why I would like this functionality: Think of a trip report. It contains some text (the actual trip report) plus a collection of photos (the trip gallery). Instead of seperating the two things by creating two different posts, I would like to create only one post with the text as content and the photos as attachments.

Then I would also like to allow the visitor to

a) read the post as a standard blog entry with standard output without the photos by calling .../blog/post-name

b) view the post as a photo album (e.g. thumbnail page) by calling .../gallery/post-name

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

One post cannot (and should not) have two single post URLs. All you can change is the archive view, the list of posts.

If /gallery/ and /extra/ are post of the post type page, use a custom page template for those.

Update

Create two endpoints gallery and extra for the root (EP_ROOT) (another example). The callback function for those endpoints the has two options:

  1. If the endpoint variable value is TRUE (/gallery/ was called without a post name), render an archive listing.
  2. If there is a string value, use get_page_by_path() and fetch the post object. Render it.

Example for get_page_by_path():

$post = get_page_by_path( 
    get_query_var( 'gallery' ), 
    OBJECT, 
    'post' 
);
share|improve this answer
    
Thanks. Please check my addition to the original question for the reasoning behind this question. –  Dreamingof8a Nov 24 '12 at 6:24
    
... maybe you have a bette ridea how to deal with this situation? –  Dreamingof8a Nov 24 '12 at 6:28
    
Actually, can I not (in theory) use URL rewrite rules to redirect as many URLs as I want to the same page (in this case the same post)? –  Dreamingof8a Nov 24 '12 at 6:34
    
@Dreamingof8a See my update. –  toscho Nov 25 '12 at 9:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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