Create a php page-template

jdunhin

Active member
Registered
Joined
Feb 27, 2013
Messages
72
Points
0
Want to share some code that I used in my new Wordpress plugin. Maybe you can get something out of it.

It is about creating a page-template.php and insert the necessary code in that page to make it one of the templates to use on a page.

Create page:
PHP:
<?php
$FileName = "example.php" ;
$FileHandle = fopen($FileName, 'w') or die("can't open file");
fclose($FileHandle);
?>
Insert code into the new page:
PHP:
<?php
$filename = "example.php";
$content = '<?php' . ' get_header(); ?>'
      . "\r\n\r\n"
      . '<div id="main_content" class="clearfix">'
      . "\r\n\r\n"
      . '<div id="left_area">'
      . "\r\n\r\n"
      . '<div id="sidebar-tuisblad" class="sidebar">'
      . "\r\n\r\n"
      . '<?php dynamic_sidebar'
      . '("' . $variable. '");'
	  . "\r\n\r\n"
      . '?> </div> </div> '
      . "\r\n\r\n"
      . '<?php get_sidebar();'
      . "\r\n\r\n"
      . ' ?> </div>'
      . "\r\n\r\n"
      . '<?php get_footer();'
      . "\r\n\r\n"
      . '?>';	  


if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }

    echo "Success, wrote ($content) to file ($filename)";

    fclose($handle);
	
} else {
    echo "The file $filename is not writable";
}

?>
 
Older Threads
Replies
14
Views
4,682
Replies
0
Views
1,665
Replies
3
Views
2,388
Replies
8
Views
4,931
Replies
22
Views
6,379
Newer Threads
Replies
0
Views
1,800
Replies
3
Views
5,382
Latest Threads
Replies
1
Views
96
Replies
4
Views
115
Recommended Threads
Replies
4
Views
1,711
Replies
0
Views
1,940
Replies
10
Views
4,167

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top