I know the title seems little bit confusing, but what I am looking for is something possible in symfony or ror. I have a page with this URL: /
. Now I want this URL structure ,
. Now the parameters after
/job/
are dynamic, and they are not any page or post, they fall under a page job
Is this possible in Wordpress?
UPDATED QUESTION:
Ok as per @Gioia's answer I updated my code.
Below is my code:
add_filter('query_vars', 'add_query_vars');
function add_query_vars($aVars) {
$aVars[] = "job_title";
$aVars[] = "job_id";
return $aVars;
}
add_action( 'init', 'add_rules' );
function add_rules() {
add_rewrite_rule('^/job/([^/]*)/([^/]*)/?','index.php?page_id=13338&job_title=$matches[1]&job_id=$matches[2]','top');
}
So now this is throwing me 404 page when I try this URL . But when I try this URL
.php?page_id=13338&job_title=php-dev&job_id=45
it works.
I know the title seems little bit confusing, but what I am looking for is something possible in symfony or ror. I have a page with this URL: http://mydomain/job/
. Now I want this URL structure http://mydomain/job/php-developer/45
, http://mydomain/job/java-developer/46
. Now the parameters after /job/
are dynamic, and they are not any page or post, they fall under a page job
Is this possible in Wordpress?
UPDATED QUESTION:
Ok as per @Gioia's answer I updated my code.
Below is my code:
add_filter('query_vars', 'add_query_vars');
function add_query_vars($aVars) {
$aVars[] = "job_title";
$aVars[] = "job_id";
return $aVars;
}
add_action( 'init', 'add_rules' );
function add_rules() {
add_rewrite_rule('^/job/([^/]*)/([^/]*)/?','index.php?page_id=13338&job_title=$matches[1]&job_id=$matches[2]','top');
}
So now this is throwing me 404 page when I try this URL http://mydomain/job/php-dev/45
. But when I try this URL http://mydomain/index.php?page_id=13338&job_title=php-dev&job_id=45
it works.
1 Answer
Reset to default 5Not completely sure I understand what you mean with that the parameters fall under a page job, but if you mean that different contents are loaded on the same page using javascript / ajax, you could use https://github/browserstate/history.js/ to generate the corresponding url for each state. Difficult to say more about how you could implement this without knowing more about what you are trying to do.
UPDATE
I think you should use custom rewrite rules. That is what wordpress uses to create the nice urls, and it has an API to add your own.
First you need to add the tags you need to track, in your case title and job_id. Actually you should probably change title to something like job_title, I am not completely sure title would create a problem, but since it is something in wordpress, it is better to be on the safe side.
I used the following code, you need to add it to your function.php, in your theme.
add_filter('query_vars', 'add_query_vars');
function add_query_vars($aVars) {
$aVars[] = "job_title";
$aVars[] = "job_id";
return $aVars;
}
More info: http://codex.wordpress/Rewrite_API/add_rewrite_tag
Then you add the rewrite rule, also in functions.php:
add_action( 'init', 'add_rules' );
function add_rules() {
add_rewrite_rule('^job/([^/]*)/([^/]*)/?','index.php?page_id=12&job_title=$matches[1]&job_id=$matches[2]','top');
}
You should replace the page_id by the id of the job page More info: http://codex.wordpress/Rewrite_API/add_rewrite_rule.
Once you have saved the file, you need to go to settings -> permalinks and simply save without changing anything. That will make sure your settings are correctly loaded.
You can install the plugin rewrite inspector to see all the rewrite rules applied and check that yours are present. https://wordpress/plugins/rewrite-rules-inspector/
You can install the plugin debug bar to inspect the page and see what rewrite rule is being applied to the page: https://wordpress/plugins/debug-bar/
And here you have more info on rewrite rules in general: http://www.addedbytes/articles/for-beginners/url-rewriting-for-beginners/
UPDATE 2
To retrieve the parameters:
if (isset($wp_query->query_vars['job_title'])) {
$job_title = urldecode($wp_query->query_vars['job_title']);?>
<?php }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745151240a4613879.html
/job/job-title/
by using a custom post type and possibly/45
by doing a custom structure with your post type. – Howdy_McGee ♦ Commented Jun 18, 2014 at 13:42/job/php-developer/45
,/job/java-developer/46
etc – Niraj Chauhan Commented Jun 18, 2014 at 14:21http://mydomain/job/?title=php-developer&job_id=45
, but to make this URL SEO friendly, I want something like thishttp://mydomain/job/php-developer/45
– Niraj Chauhan Commented Jun 18, 2014 at 14:52