I use WordPress to run a few other websites, such as my CommunityHost site, and wanted to add a form to support a mailing list. My hosting company, Servage, supports mailing lists and I’ve used them with some success, so I didn’t need to re-invent the wheel and decided that the best bet would be to somehow get the HTML form that Servage supply on to a WordPress page.
I did try the obvious – just paste the HTML source code in to a page – and that was about as effective as the proverbial cat flap in an elephant house. So I then decided to create a new template page containing the code. And for all who’re interested, here’s what I did in Version 2.3.x.
Create a blank page
In the relevant theme folder I copied the existing PHP file that is used as the basis for displaying pages on the site. The name of this file varies between themes, but typically it will be soemthing like ‘page.php’. Anyway, copy this and rename it to something like ‘mailinglist.php’, and leave it in the same folder. Also, use FTP to set the file to be writable.
Convert to template
Go in to the Presentation->Theme Editor option for the Theme you’re modifying, and your new page should be listed with all the others. Click on it to open the file up in the editing window, and then add the folloiwng code as the first thing in the file:
<?php /* Template Name: Servage Mailing List */ ?>
This sets the Template Name to, in this instance ‘Servage Mailing List’. Save this change and you should see the page is now listed as ‘Servage Mailing List’ in the list of pages.
Add the HTML Code
The Servage Mailing List management program generates a simple form that you can paste in to a web page. All I needed to do now was to add this code in to the Template. Reload the template and locate the code that brings in the content for the page. This will be something like:
<?php the_content(); ?>
and it will be in a suitably named DIV in the page. Again, exact details of the line will vary from Theme to Theme, but look for ‘the_content()’ or similar.
Now, if you want to be able to add content to the page later, leave this line in. If your new Mailing List page will just contain the form, remove this line. You can then simply paste in the HTML Form code provided by Servage.
This approach is applicable to ANY similar requirements where you want a static HTML page within the context of a WordPress page.
Save the changes.
Adding the Page
We now have a Template that can be used to provide a Page. This is a pretty limited Template; it has been created with one particular purpose in mind, but it works well. To add a page based on it, Add a new Page from the ‘Write’ menu, then open up the ‘Page Template’ tab on the right hand side and set the Template to whatever you’ve named your template – in this case ‘Servage Mailing List’.
The finished result is seen here, on my CommunityHost site.