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 currently have these custom permalink rules:

/%category%/%postname%/

I'd like /%category%/%postname%/%sometext% to display the same as /%category%/%postname%/ - from there, I will either use PHP or jQuery to display different content on the page.

EG:

/about-us/team/mike to display the /about-us/team page, and then I'll highlight 'Mike's bio' with jQuery.

Thanks

share|improve this question
    
This is functionally identical to the use of # and IDs to auto navigate to places on a page, what you're trying to do sounds terribly like a kludge/work around. Why do you wish to do this? –  Tom J Nowell Jan 15 '13 at 11:25
    
Mainly for SEO purposes. –  Martin Alderson Jan 15 '13 at 13:51
    
If it helps, this is pretty much exactly what I want to achieve: wordpress.org/support/topic/… –  Martin Alderson Jan 15 '13 at 14:34
    
hmmm I'm doubtful that this will be of any use SEO wise, especially since correct use of canonical urls in the head tags will mean that google will ignore these additional pages, that or it will penalise you for duplicated content –  Tom J Nowell Jan 15 '13 at 14:56
    
Yeah, I know it is a bit of a cludge. All I want to do is wordpress to 'ignore' anything after the www.sitename.com/%category%/%postname% - so I can process it on page. –  Martin Alderson Jan 15 '13 at 15:50
show 2 more comments

1 Answer

up vote 0 down vote accepted

You will need to whitelist a new query_var:

function add_query_vars($aVars) {
    $aVars[] = "subpage"; // represents the name of the product category as shown in the URL
    return $aVars;
}

// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_query_vars');

You will need then need a rewrite rule to match your URL and pass in the correct query variables:

add_rewrite_rule('([^/]+)/([^/]+)/([^/]+)?','index.php?pagename=$matches[1]/$matches[2]&subpage=$matches[3]','top');

Finally on your pages template, you'll want to look for that query var, e.g.

if( !empty(get_query_var('subpage') )){ 
    // do subpage stuff
    $subpage = get_query_var('subpage');
    // process above value
} else { 
    // not on subpage, do normal page stuff 
}

Flush permalinks and you're good to go.

You should probably make good use of get_template_part, how you store the subpage data is up to you, post meta might work, just remember that it won't be searchable by default but there are other questions that can answer that problem

share|improve this answer
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.