Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have used PHP on a page to include HTML files on a page such as:

<?php require("http://www.mysite.edu/_sports/static/season_box.html"); ?>

This works well for including a single file that gets updated frequently.

I am hoping to find a way to use PHP code in a single Wordpress Page that would included one of several HTML files depending on the URL. The idea would be to be able to create a URL to a Wordpress page that would have the name of the HTML file as a variable that the PHP script would use to identify the desired HTML file to include.

share|improve this question
2  
Hi Ron, welcome to WPSE! Some explanation about your question title: The URL value is named "query part" of a "query string". I'm sure google will give you enough results, so you can get back and bring this question on topic and make it easier to understand. Thanks. –  kaiser Sep 23 '12 at 8:37

1 Answer 1

Assuming you already set permalinks for your Wordpress site, add this to your page.php:

 <?php 
    include("http://www.mysite.edu/_sports/static/".$post->post_name.".html); 
 ?>

$post->post_name would be the slug of your page.

If you're in a page with the slug volleyball-box-score, with the code above, you would get include("http://www.mysite.edu/_sports/static/volleyball-box-score.html);. If you're in a page with the slug other-page, you would get include("http://www.mysite.edu/_sports/static/other-page.html);. Etc.

share|improve this answer
    
I've been playing around with this for about an hour, but I don't think this does the trick. I have created a page with a slug of volleyball-box-score. If I want to use this page to access, let's say, three different html files named: box1.html, box2.html and box3.html. What would be the URL for accessing box1.html as opposed to box3.html? –  Ron Smith Sep 23 '12 at 7:14
    
I apologize. I could be very well misunderstood your request. If you want to access box1.html, you could simply use <?php include("http://www.mysite.edu/_sports/static/".$post->post_name.".html); ?>, but I guess that's not the case, right? I'm a bit confused on what do you mean by "I am hoping to find a way to use PHP code in a single Wordpress Page that would included one of several HTML files depending on the URL.". :s What do you mean by "depending on the URL"? –  deathlock Sep 23 '12 at 8:11
    
No apology needed, I appreciate the help. Here is what I am trying to accomplish through a Wordpress page with the slug volleyball-box-score. I would like to be able to create a link that would include a variable equal to the HTML file I want included. In one place, the link might read "mysite.edu/_sports/static/volleyball-box-score?=box1.html"; and volleyball-box-score would return the contents of box1.html. In another place, the link might read "mysite.edu/_sports/static/volleyball-box-score?=box3.html"; and volleyball-box-score would return the contents of box3.html. –  Ron Smith Sep 23 '12 at 16:01
    
I meant to say: Here is what I am trying to do through a Wordpress page with the slug volleyball-box-score. I would like to be able to create a link that would include a variable equal to the HTML file I want included. In one place, the link might read "www.mysite.edu/_sports/static/volleyball-box-score?file=box1.html" and volleyball-box-score would return the contents of box1.html. In another place, the link might read "www.mysite.edu/_sports/static/volleyball-box-score?file=box3.html" and volleyball-box-score would return the contents of box3.html. –  Ron Smith Sep 23 '12 at 16:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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