0

I created a page called Catalog and also a template called page-catalog.php. The url looks like this now: sitename.com/catalog

So far so good, however i use some custom php stuff to list products from another database. So when i click on a brand in this page, i want to use an url like this: sitename.com/catalog/brands/brandname

But obviously because the data is not coming from Wordpress, it gives me 404. Is it possible to use the same page-catalog.php file if the url has more parts?

I could use an url like this: sitename.com/catalog/?brand=brandname But this solution is not so sep friendly.

1
  • Your question really isn't about disabling the 404 page, as it is about how to combine external DB data with WordPress data. May 24, 2012 at 16:07

1 Answer 1

0

You could use a WordPress rewrite (as opposed to mod-rewrite) to solve the issue.

function createRewriteRules( $rules ){
    $newrules = null;
    $newrules = array();
    $newrules["catalog/?$"] = "index.php?page=xx";
    $rules = $newrules + $rules;
    return $rules;
}

add_action('rewrite_rules_array', 'createRewriteRules');

You'll need to flush the rules:

http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

Your page-catalog.php file could then sniff the original url and do some processing as required.

6
  • Thanks, i just tried it, but it's not working. .com/catalog loads up my index.php, .com/catalog/anything gives me 404.php
    – passatgt
    May 24, 2012 at 17:14
  • Did you flush the rules? (A quick way is in WP Admin, change your permalink structure to something different, save, and then change it back and save).
    – Roscius
    May 24, 2012 at 18:19
  • Also, try with the function in a plugin as opposed to functions.php
    – Roscius
    May 24, 2012 at 18:20
  • Yes, that was the problem, thanks! Maybe i can mess with the add_action location, like add_action=init to make this work from the functions.php
    – passatgt
    May 26, 2012 at 8:27
  • It's most likely that functions.php doesn't work because it loads fairly late in the bootstrap process, loading the rewrite rules too late may have other unintended consquences - they're used to determine a bunch of things, most importantly what template to load.
    – Roscius
    May 26, 2012 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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