最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I create a single Wordpress page that will use PHP to include different HTML files based on a vaule in the URL?

programmeradmin4浏览0评论

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

<?php require(".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.

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 edited Sep 23, 2012 at 5:30 Ron Smith asked Sep 23, 2012 at 5:13 Ron SmithRon Smith 111 bronze badge 1
  • 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 Commented Sep 23, 2012 at 8:37
Add a comment  | 

1 Answer 1

Reset to default 0

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论