Grow your CSS skills. Land your dream job.

Backend-editable footer sentence

  • # February 7, 2009 at 2:21 pm

    I have a wordpress 2.7 site on which I am trying to create a small sort of About Us sentence in the footer (much like Chris’s About the Author in the footer of CSS-Tricks). Now this itself is not hard at all, but I would like to be able to edit what this About Us thing says from within the wordpress backend. My initial reaction was to make a plugin, which I have nearly got working.. but the plugin is not my question yet. I am wondering if anyone has a better idea on how to go about doing this. If a plugin is the best way to go then I’ll post what I’ve done so far, it just seems that there might be an easier way to do this.

    # February 7, 2009 at 2:49 pm

    from within wordpress, I think it would have to be a plugin,

    I can’t see anything in wordpress that will work with the footer from within wordpress, as in the back end.

    why would you not want to change the footer file and upload? why would you want to change the footer so often that you need wordpress?

    # February 7, 2009 at 3:10 pm

    Well, if it was for me, I would just change the file and upload. And actually the editable footer isn’t extremely important as it won’t be changed too often. But, there is a similar sentence in the header which will be changed more often. I was hoping to end up using the same technique/plugin on that too since its basically the same thing.

    # February 7, 2009 at 9:32 pm

    My theory is that creating a custom panel with the functions.php file is the best way to go. I’d really like to figure this out as it could be useful for all kinds of stuff I think. I’ll look into it, we’ll see :geek:

    # February 7, 2009 at 11:05 pm

    I’ve attached what I’ve done so far on the plugin. It works quite well besides that when you Save Changes on the admin page it forwards to the blank options.php with only the footer displayed. I’m sure there is a fix for that, but being my first plugin I’m guessing I just did something wrong.

    I was thinking about plugin vs function.php
    With the plugin, it can be distributed.. because who knows, people might want this sort of functionality in their other pre-downloaded theme.
    But with functions.php it would be theme specific.. which is also okay. But not everyone with a certain theme will need this functionality.

    But for now, I’ll use whatever works. Don’t exactly have to decide on plugin vs functions until later. After it works and if other people actually want it.

    # February 8, 2009 at 4:05 pm

    I just tested it out and it’s a little funky, but it works! Activating it did bring me to that blank page. When I save the text, it also brings up a nasty warning on an otherwise white page:

    Quote:
    Warning: Cannot modify header information – headers already sent by (output started at /nfs/c02/h02/mnt/21410/domains/jeffcampana.com/html/wp-content/plugins/editable-template-tags/editable-template-tags.php:11) in /nfs/c02/h02/mnt/21410/domains/jeffcampana.com/html/wp-includes/pluggable.php on line 850

    But… press the back button in the browser and the text DOES save. I’ve used it to control the text in the footer on a new site I built for a friend:
    http://jeffcampana.com/

    # February 8, 2009 at 5:50 pm

    Its quite a long code, but this is what i used to do the same thing for a website recently. The Client wanted a way to put news and traffic updates on their site, and have them update it in wordpress.

    Add this code to functions.php:

    Code:
    < ?php
    /* New control panel class */
    class ControlPanel {

    /* Store DEFAULT SETTINGS in an array..and create a variable to store options. */
    var $default_settings = Array(
    'theNews' => ‘The News!’,
    ‘theTraffic’ => ‘The Traffic!’,
    );

    var $options;

    /* Create new control panel function and defines administration menu, and head you do not need to modify anything in this part */
    function ControlPanel() {
    add_action(‘admin_menu’, array(&$this, ‘add_menu’));
    add_action(‘admin_head’, array(&$this, ‘admin_head’));

    /* The following code simply add options. and note the word ‘mytheme’ this can be changed to your theme name actually you just need to make all of them look same. */
    if (!is_array(get_option(‘mytheme’)))
    add_option(‘mytheme’, $this->default_settings);
    $this->options = get_option(‘mytheme’);
    }

    /* This adds administration menu: Under Design, it adds a theme page called Simple Control Panel and also notice how I didn’t change mytheme name */
    function add_menu() {
    add_theme_page(‘Control Panel’, ‘Control Panel’, 8, “mytheme”, array(&$this, ‘optionsmenu’));
    }

    /* Here you put your form CSS. The control panel form has a class of themeform. so Just create your stylesheet here for themeform fields, inputs, etc…I will leave this part for you as its really easy */
    function admin_head() {}

    function optionsmenu() {
    if ($_POST['ss_action'] == ‘save’) {
    /* This is just to update the boxes every time we update the form */

    $this->options["theNews"] = $_POST['cp_theNews'];
    $this->options["theTraffic"] = $_POST['cp_theTraffic'];

    update_option(‘mytheme’, $this->options); /* Tells wordpress to update your options.. */

    echo ‘

    Your changes have been saved.

    ‘; /* Displays successful message.. like changes have been saved! */
    }

    /* That is all.. lets print the form to browser */
    echo ‘

    ‘;
    echo ‘
    ‘;
    echo ‘‘;

    echo ‘

    ‘;
    /* Field for theNews */
    echo ‘

    ‘;

    /* Field for theTraffic */
    echo ‘

    ‘;

    /* The default value is Welcome to my blog! but you can always change that..just as a very simple example */

    echo ‘

    ‘;
    echo ‘

    ‘;

    echo ‘

    ‘;

    }

    } /* Quit Control Panel Class. Very important! */
    ?>
    < ?php
    $cpanel = new ControlPanel(); /* This initiates a new control panel object */
    $mytheme_options = get_option('mytheme'); /* This creates a variable and store your option in it to be able to call it in your template */
    ?>

    Replace theNews and theTraffic whereever you see them (in your case footersentence and headersentence).

    When you logon to wordpress, you should see a menu called "Control Panel" in the Appearance section. In it will be two text boxes which you can put whatever you want in.

    Now, add the following to any wordpress page (index.php, footer.php etc)

    Code:
    < ?php global $mytheme_options; print $mytheme_options['theNews'];?>

    < ?php global $mytheme_options; print $mytheme_options['theTraffic'];?>

    i think this should work

    # February 8, 2009 at 9:18 pm

    Yeah, I wouldn’t recommend using my plugin quite yet, it also seems to prevent posting and navigating around some parts of the backend… I obviously did something wrong somewhere. For now I’ll try out what chazzwick has posted and see what I can do with that.

    Edit: It works quite well. Maybe I’ll attempt to convert it to a plugin if chazzwick doesn’t mind. Key word there is "attempt".

    # February 9, 2009 at 11:02 am

    its not my code, this is where i got it from http://www.webloglines.com/blog/stuff/article/building_a_control_panel_for_your_wordpress_theme.php

    Youd have to ask them

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".