I have a site with a custom home page, home.php. What’s the right way to present the editable home page options in the admin tool?
For example, there’s a few custom text fields on the home page that should be editable in the admin tool. I’m looking for the best way to set this up so an admin user can change these options.
UPDATE: imagine a site with a home page with a promotional blurb (text string) that I need to be able to let admin users (non-tech people) update easily. I’m trying to figure out how to present a screen in admin that says “What promotional text do you want on the home page? [______________]”? I thought about doing this via widget but that route is clunky and requires me to create a special sidebar just to hold the single widget. What’s the best way to approach this?
6 s
There are many solutions to this problem. And every one of them is correct, I guess. It depends on what you really want and what will be most friendly/clear to user/administrator of this page.
I usually use 3 ways to solve this. Which one of them I chose? It depends on situation. Sometimes I use 2 of them simultaneously.
1. Static front page solution.
When I can set static page as front page, I do it. Then create front-page.php
page template and use it to define how home-page/front-page should look like.
To display/allow to edit some custom fields on this page, I use Advanced Custom Fields plugin. It allows you to define custom fields set for front-page (and much more). Then I use front-page.php
template to show these custom fields values, where they should be shown.
If some of these values should be repeated on every page (in footer, in header, etc.) I get these values from Home Page like this:
$cf_value = get_post_meta( get_option('page_on_front'), '<CUSTOM FIELD NAME>', true );
It’s very easy and clean solution, when there are not many fields that should be repeated on other pages. It’s user friendly to, I guess. If you want to edit home page, you just have to go and do it – you can edit everything in home page editor.
2. Universal solution.
The other solution I use is to define some theme options. It is much better when you want to define look of page (logo image, backgrounds, and so on), and not only the content (especially if you mean the content of only one page).
I usually use OptionTree plugin to do this. But it’s not so hard to do this by yourself.
I don’t really like the idea, that you should edit content of the page in theme options, so I don’t use this solution very often.
3. When this content is always repeated on other pages
Sometimes you have to show some values on every page (or most of them) and not only on home page. Then the “nicest” solution, I think, is to define these areas as sidebars and allow user to edit them using widgets.
If this repeating content is just one line (copyright info line in footer, etc.) and it won’t be changed to often, I probably would use solution 1. But if it’s more complex or it will be changed often, this solution is best, I guess.