The MU forums have moved to WordPress.org

Dynamic subpages (5 posts)

  1. yossin
    Member
    Posted 14 years ago #

    Hi all -
    I would like to present to you a problem I am experiencing now:
    Suppose i have in my wordpress the page: http://www.example.com/trees
    This page contains list of 100 types of trees. Each link references to a url of the form: http://www.example.com/trees/tree-type which holds all the information about this certain type of tree.
    Since I don't want to create 100 subpages, I've decided to rewrite this URL into http://www.example.com/tree.php?type=tree-type using the .htaccess file.
    The rewrite works fine, however, tools like fiddler and wget will show you what's really going on behind the scenes: WordPress throws HTTP 404 message because http://www.example.com/trees/tree-type doesn't exist.

    My question is how do I prevent from WordPress to do it?

    Will be very happy if you could figure out something preserving the pretty permalinks of the subpages.

    Thanks

  2. ancawonka
    Member
    Posted 14 years ago #

    Just out of curiosity why don't you want to create 100 sub-pages? Do you have some other database of trees you're using?

    What does tree.php do? is the PHP file located directly inside your WordPress theme, or in the site root folder? (In other words, can you access /tree.php?type=tree-type and get the right tree returned?)

  3. yossin
    Member
    Posted 14 years ago #

    Just out of curiosity why don't you want to create 100 sub-pages? Do you have some other database of trees you're using?

    It seems to me like a waste of time to create 100 subpages which have identical template of information in every one of them. The database of the trees doesn't reside in wordpress db. Why can't I create one PHP file which takes the tree type as an argument and produces the desired data on the certain tree?

    What does tree.php do? is the PHP file located directly inside your WordPress theme, or in the site root folder? (In other words, can you access /tree.php?type=tree-type and get the right tree returned?)

    tree.php is responsible for presenting the data related to the certain type of tree. Imagine that instead of creating a special subpage for each tree-type, I make just one page which takes care of all of them and I don't need to insert into the database 100 posts/pages. Does file location matters? For discussion's sake, its location is in the theme folder

    Thanks for your reply

  4. DeannaS
    Member
    Posted 14 years ago #

    You can do it, but you need to register the wp query variables for the rewrites. Take a look at the sample theme code here for an example of how to do the rewrites:

    http://wordpress.org/extend/plugins/blog-topics/

    (In the sample themes files you're looking for rewrites.php and either sites.php or topics.php.)

  5. yossin
    Member
    Posted 14 years ago #

    DeannaS -
    Sorry if I missunderstood you but these rewrites you did in rewrites.php come instead of the RewriteRules in .htaccess file ?

About this Topic