• I want to create a number of themes. These themes should be “plug-n-play” out of the box – install and go. To that end, I want to create “true” static pages, like a standard privacy policy, terms, perhaps a contact form. I don’t want the end-user to have to move anything around or have to run any special install scripts.

    What I need to know is the best approach to do this in the WP realm. So far I’ve thought of….

    Adding the static pages to the theme directory and perhaps linking to them. I actually tried this, but it appears I need to jump through “include” hoops. I’m not 100% certain how to do that. My first attempt resulted in a 404 page, and after that I just got PHP function not found errors.

    I suppose I could automatically create WordPress pages when the theme is activated using the functions.php file. That seems a bit dicey to me – too many ways for that to end badly. Or, I could just have the functions.php file load a purely static page from somewhere.

    I could “game” the 404 page. In other words, in the 404 script I could check to see if the slug matches one of my static pages and load the static page up in the content area.

    I’m leaning a bit toward the last option since it’s something I know I can code. But, if someone has a better/cleaner solution, I’d like to hear about it.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’re dealing with both creating the static pages and the content (such as privacy policies, terms of use boilerplate, contact form fields, etc.) So maybe you’d want to include a php script that will write to wp_posts and wp_postmeta and dump in the pages and the content while leaving the rest of the WP install and database alone. That way you get your static pages setup and the content entered outside of the theme the user chooses.

    I suppose I could automatically create WordPress pages when the theme is activated using the functions.php file. That seems a bit dicey to me – too many ways for that to end badly. Or, I could just have the functions.php file load a purely static page from somewhere.

    You could always create page templates, holding static text, but you’ld have to assign them to a page anyway (which has to be created).

    Peter

    Thread Starter WWDay3

    (@wwday3)

    I hesitate automatically writing to the database. I’ve had plugins in the past that automatically wrote wp-pages, and in a couple of cases I wound up with duplicates. I wouldn’t want to overwrite an existing page or create a dup if the slug already existed.

    I did experiment, and was able to get static pages to work without too much trouble. I simply looked for the slug in the 404.php file, and depending on which slug it is, I include the appropriate page. My worry – that the 404 page would return a 404 error code – was ill founded. Apparently the WP developers decided to return a 200 code since they were trapping the 404 condition anyway.

    Advantages – simple, tightly bound, and I was able to use a contact form that looks better (IMO) than most of the plugin contact forms. Plus, as I was coding I realized that if someone just hated my privacy policy or terms or whatever, they could just create a page with the same slug and it would be intercepted before getting to mine.

    Disadvantages – not “WordPressy”, not turn-off-able in its present form (e.g. – if someone never wanted to be contacted they would still have to touch the footer code).

    So, even though it works out-of-the-box right now, I don’t think it’s the final solution. I probably still need an options page of some sort.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘True static pages?’ is closed to new replies.