1

I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.

I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.

So i tried to: <?php $html = file_get_contents('http://www.mydomain.com/homepage-featured'); ?>

The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.

The above code doesn't work.

Thanks for the help.

1
  • Ok I will try to clarify this question because perhaps i am doing this wrong. I go into wordpress>editor>featured.php I put my HTML in this file and it displays correctly in my browser as intended. However I prefer to put my HTML in a separate page located at: www.url.com/myhomepage Commented Dec 22, 2011 at 22:47

4 Answers 4

3

file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.

Sign up to request clarification or add additional context in comments.

2 Comments

the page is on the same server. I just want it to display in the section which is defined as "featured" Does that make sense?
I suppose it makes. In this case you can use its relative or absolute location like "../directory/myfile.php"
0

I think you have better to use the include function.

The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.

1 Comment

the page is on the same server. I just want it to display in the section which is defined as "featured" Does that make sense?
0

Have you tried

<?php
    require('http://www.mydomain.com/homepage-featured');
?>

1 Comment

Ok i tried this, however it just shows "loading" and the rest of the page doesn't load. Any ideas?
0

If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.

To do so, just change the Page Template of the page(the separate page which is @ www.url.com/myhomepage). You can change this @ Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".

(I assume that your code in file feature.php has Template Name: Featured at the top)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.