• Okay, basically I have a fairly simple site with around 15 pages. But one of the sections contains information on people, and there are over 150 people in this database.

    What I want is for http://www.site.com/people/ to show all the people, and then http://www.site.com/people/person_1/ to show their details, but as we are constantly changing the database, I don’t want to have to create individual pages for each person.

    I’m basically looking for a way to have these pages exist within a WordPress site, but pull the information from a separate database. I thought about just creating a separate directory /people/ and doing it all manually, but I want to keep the header/footer information from WordPress consistent throughout the site.

    Any suggestions?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I had a site exactly like what you are describing written in Etomite, another Open Source CMS. When I made the move to WordPress last May, I opted to hand create each person-details page to avoid constantly revising the external (i.e. – non-WordPress) database structure whenever I discovered a new type of info I wanted to add for one or more people. Plus, I didn’t want to build my own database-based picture gallery like I had to in Etomite, opting for WordPress’s built-in gallery.

    But I retained the automatic linking from the All-People page to the Person-Details page by checking if a WordPress child page existed with the person’s name (which I used as the Page Title).

    I’m not saying that what you propose isn’t possible. I’m just saying that I chose my approach as it was easier and more flexible. Though I did do a lot of Copy and Paste.

    Thread Starter Trevor Gehman

    (@trevorgehman)

    Thanks for the reply.

    I really want to avoid having to create that many individual pages, mainly because the database of people is constantly being updated by an external admin interface (which we custom built). It wouldn’t be practical to switch over, UNLESS there were a way to let it create pages automatically (maybe by accessing the WordPress database directly?) But that sounds like a huge PAIN.

    Alternatively, I could create a custom directory with PHP files that call the WordPress header and footer files, and just keep that directory separate.

    Honestly, I’m leaning toward the second solution. My ONLY HESITATION is that say for the Google XML Sitemap plugin, it wouldn’t be aware of these pages, would it? Might make the site fragmented, which I want to avoid. On the other hand, the shopping cart area of the site will ALSO be outside of WordPress….

    Thread Starter Trevor Gehman

    (@trevorgehman)

    Anyone else have any input?

    You should be able to create a new theme template for ‘people’ and feed it an url something like ‘people/?person=person_1’ then have a function in the template connect to your external database and grab the person’s data. You should be able to connect to any database you want so long as you have the right login, pass, and privileges. Then use WP_Rewrite to get the user friendly URL structure you want.

    Thread Starter Trevor Gehman

    (@trevorgehman)

    Hey man just wanted to say THANK YOU for this great advice.

    I think that is definitely what I’m going to do…

    You can connect to another database using a new wpdb object..

    // Example db connection
    $my_db = new wpdb( 'db_user', 'db_password', 'db_name', 'host' );
    
    // Example query using new db connection
    $results = $my_db->get_results("SELECT x,y,z FROM a WHERE b = 'c'");
    
    // Example loop to follow.
    if( $results  ) {
    	foreach( $results as $item ) {
    		echo $item->x; // Echoes the data from the x col in the query
    		echo '<br />';
    		echo $item->y; // Echoes the data from the y col in the query
    		echo '<br />';
    		echo $item->z; // Echoes the data from the z col in the query
    		echo '<br />';
    	}
    }

    If you’re querying a seperate database, hopefully that will help..

    You can also see a similiar example here, which inspired the example above.
    http://wordpress.org/support/topic/307945?replies=8

    Info on the wpdb class here(although no example of using a new wpdb object):
    http://codex.wordpress.org/Function_Reference/wpdb_Class

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress as a CMS for a site with subpages pulled from separate database’ is closed to new replies.