Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[RESOLVED] Plugin Theme : Sidebar option
#1
Hi all !

I'm working on a new template, and I wish to add an option to activate the sidebar.

I based my work on the Innovation Theme Plugin, and I created a radio box to select YES or NO to activate the sidebar.

I have got a problem, the XML file is well generated, but the option still null.

After I need to read the result, if it's YES (true) then the sidebar is displayed otherwise it's not. That is done in template.php. I am not sure how to do this.

In attachments you'll find the template, just move cyclehomePlugin.php into plugins directory.

Thank you for your help, I'm sure it's simple but it has to blind me.
Reply
#2
Here's an updated plugin file for you.

Should work as expected.

the problem was you were save the value of $_POST['sidebaractive'] whereas you should have been saving the value of your radio group 'option1'

added some code to the radio button to make sure the current value is also set.

Mike...

Code:
<?php
/*
Plugin Name: Cyclehome Theme Settings
Description: Settings for the default GetSimple 3.0 Theme: Cyclehome
Version: 1.0
Author: David Di Natale

based on the work of : Chris Cagle
Author URI: http://www.cagintranet.com/
*/

# get correct id for plugin
$thisfile=basename(__FILE__, ".php");
$cyclehome_file=GSDATAOTHERPATH .'cyclehomeSettings.xml';

# register plugin
register_plugin(
    $thisfile,                                                     # ID of plugin, should be filename minus php
    'cyclehome Theme Settings',                                     # Title of plugin
    '1.0',                                                             # Version of plugin
    'David Di Natale',                                            # Author of plugin
    '',             # Author URL
    'Settings for the default GetSimple 3.0 Theme: Cyclehome',     # Plugin Description
    'theme',                                                     # Page type of plugin
    'cyclehome_show'                                          # Function that displays content
);

# hooks
add_action('theme-sidebar','createSideMenu',array($thisfile,'Cyclehome Theme Settings'));

# get XML data
if (file_exists($cyclehome_file)) {
    $x = getXML($cyclehome_file);

    $sidebaractive = $x->sidebaractive;
} else {

    $sidebaractive = "";
}


function cyclehome_show() {
    global $cyclehome_file, $facebook, $twitter, $linkedin, $sidebaractive, $success,$error;
    
    // submitted form
    if (isset($_POST['submit'])) {
        
        $sidebaractive = $_POST['option1'];
    
        # if there are no errors, save data
        if (!$error) {
            $xml = @new SimpleXMLElement('<item></item>');
            
            $xml->addChild('sidebaractive', $sidebaractive);
            
            if (! $xml->asXML($cyclehome_file)) {
                $error = i18n_r('CHMOD_ERROR');
            } else {
                $x = getXML($cyclehome_file);
                $sidebaractive = $x->sidebaractive;
                $success = i18n_r('SETTINGS_UPDATED');
            }
        }
    }
    
    ?>
    <h3>cyclehome Theme Settings</h3>
    
    <?php
    if($success) {
        echo '<p style="color:#669933;"><b>'. $success .'</b></p>';
    }
    if($error) {
        echo '<p style="color:#cc0000;"><b>'. $error .'</b></p>';
    }
    ?>
    
    <form method="post" action="<?php    echo $_SERVER ['REQUEST_URI']?>">
        
        <p><label for="sidebaractive" >Activate Sidebar ?</label><input type="radio" name="option1" value="YES" <?php if($sidebaractive=="YES") echo "checked"; ?>> YES <input type="radio" name="option1" value="NO" <?php if($sidebaractive=="NO") echo "checked"; ?>> NO <br>
        
        <p><input type="submit" id="submit" class="submit" value="<?php i18n('BTN_SAVESETTINGS'); ?>" name="submit" /></p>
    </form>
    
    <?php
}
My Github Repos: Github
Website: DigiMute
Reply
#3
Thank you n00dles101 !

Can you tell me how to read the value of sidebaractive in my template ?

edit : i find it !
Code:
<?php
    $x = getXML($cyclehome_file);
    $sidebaractive = $x->sidebaractive;
    if ($sidebaractive == 'true')  {
        include('sidebar.php');
    }
?>
Reply
#4
It's either going to be set to 'YES' or 'NO' so change the code to

Code:
<?php
    $x = getXML($cyclehome_file);
    $sidebaractive = $x->sidebaractive;
    if ($sidebaractive == 'YES')  {
        include('sidebar.php');
    }
?>
My Github Repos: Github
Website: DigiMute
Reply
#5
yes, I tried to read the value with a bad method, I changed the value yes or no to true or false.

After I found the solution, and I left the default value to true or false.

I modified your code accordingly.

Now my template is able to adapt to the presence of the sidebar in terms of size.
The code in the template is as follows:
Code:
<div id="site_content">
    <?php
        $x = getXML($cyclehome_file);
        $sidebaractive = $x->sidebaractive;
        if ($sidebaractive == 'true')  {
            include('sidebar.php'); /* edit sidebar.php to add all plugin element's needed */
            echo '<div id="content">';
        } else {
            echo '<div id="content-nosidebar">';
        }
        get_page_content();
        echo '</div>';
    ?>            
</div>

Thank you for your attention n00dles101 Wink

ps : sorry for my very bad english, I try my best ^^
Reply
#6
No problem. Glad you got it working....
My Github Repos: Github
Website: DigiMute
Reply




Users browsing this thread: 1 Guest(s)