I am a bit confused about how WordPress's permalink works, especially beyond Wordpress's own usage. My permalinks are like:
%post_id%-%post_name%
But in single.php
I want to put another link to page itself but with different query string. When it is clicked the permalink structure may look like:
%mystring%-%post_id%-%post_name%
I want to get the value from $_GET['action']
, so:
$_GET['action'] = %mystring%
my plan is to interpret it like:
if('xx' == $_GET['action']){
//do xx stuff
} else if ('yy'==$_GET['action']){
//do yy stuff
} else {
//show the single post as a single.php always shows
}
that means, I want to parse the $_GET['action']
optionally. If I do not parse it even if it is available in query string, I want the page to be rendered correctly.
So to get this done, where should I actually work? Also how do I form the link for <a>
tag? Usually we make link this way:
<a href="'.the_permalink().'">TEXT</a>
but you already know, I need to add some text before the original permalink of post.
Thanks in advance.
Leave your permalink structure as it was and check out my answer on custom rewrite rules.
You could adapt the code like so;
Now the page
my_page
should be available athttp://example.com/whatever/my_page
andhttp://example.com/my_page
.You can get the value of
whatever
usingget_query_var('my_action')
.Disclaimer
This may have undesired effects when viewing children pages or page attachments. You could get around this by passing an identifier in your rewrite, something to the effect of;
Note: You will need to edit the rewrite rule if you wish to do this. Every time you make changes to the code you will need to re-save your permalink structure to 'flush' the rules.