Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
WordPress: How To Save Settings and Call That Value Again?
Old 11-29-2009, 10:11 PM WordPress: How To Save Settings and Call That Value Again?
Novice Talker

Posts: 7
Name: Pangeran Wiguan
Trades: 0
Hello to all.

I need help.

I'm making a wordpress theme with some admin interface.
My mission is towards "No Hand Code For User".

After reading the WordPress codex about a week ago, I manage to register my admin page under the Appearance tab which what I want.

Now I want to put form in that page which I already know how to and yes, the form appear at that page. But I don't know where to save that options and how to call back the value of the option.

My goal is to make css selector for my users.

This is how I do it so far.

I put all the css files inside one directory and using scandir and readdir, I manage to display the css filename in <option> by using a loop.

What I want, when the users select which css file name and the click save, that file name will be saved.

And then, I will need to call the chosen filename again and then use add_action to hook it to <head> so it will import the css.

Am I making myself clear?

Please enlighten me, I have read the WordPress codex and still don't get it, and I don't have formal lesson on PHP and mySQL database. I'm just enthusiast.

Best regards,
- Guan -
wgn_white is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-30-2009, 10:06 AM Re: WordPress: How To Save Settings and Call That Value Again?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Take a look at this tutorial:
http://forthelose.org/how-to-create-...ordpress-theme

You could optionally just have a few lines of css in the head that get updated dynamically with these options such as:

#content { background-color:<?php echo $bg_color_value; ?>; }

You call back global options differently than custom fields options. (You will see in the tutorial.)
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 11-30-2009, 10:25 PM Re: WordPress: How To Save Settings and Call That Value Again?
Novice Talker

Posts: 7
Name: Pangeran Wiguan
Trades: 0
Hey, guys.

I manage to save the setting value and also being able to call the value.
Thank you for the reply.

But I have another problem.

I get this error,

Code:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\themes\wpthemestudiox2\wptsx2-includes\colour-switcher.php:12) in C:\xampplite\htdocs\wordpress\wp-includes\pluggable.php on line 865
After the submit form being submit.

I know some of you might say that delete whitespace, etc.
Cannot find anything such as, I'm using dreamweaver cs3.

Here's the code of the functions.

PHP Code:
if ( is_admin() ){

    
add_action('admin_init''wptsx2_register_colourswitcher_settings');
    
add_action('admin_menu''wptsx2_admin_reg');

}

else {

    
// Nothing. Really.

}

function 
wptsx2_admin_reg() {

    
add_submenu_page('themes.php''WPThemestudio X2 Administration''WPTS X2''administrator''wptsx2-admin/admin-page.php''wptsx2_admin_page');


PHP Code:
<?php function wptsx2_admin_page() { ?>

    <div id="wptsx2-admin" class="wrap">
    
        <h1>WPThemestudio X2 Administration Page</h1>
        <p>Change settings for your WPThemestudio X2 theme here.</p>
        
        <div id="colour-switcher">
        
            <h2>Stylesheet</h2>
        
            <div class="widefat" style="padding:8px; width:600px;">
            
                <?php wptsx2_colour_switcher(); ?>
            
            </div>
        
        </div>
        
        <div style="margin-top:30px;">
            <small>Powered by <a href="http://wordpress.org" title="WordPress">WordPress</a> & <a href="http://wpthemestudio.com/wordpress-themes/wpthemestudiox2/" title="WPThemestudio X2">WPThemestudio X2</a> by <a href="http://pangeran.org" title="Pangeran Wiguan">Pangeran Wiguan</a>.</small>
        </div>
    
    </div>

<?php ?>
PHP Code:
<?php function wptsx2_register_colourswitcher_settings() {

    
register_setting('wptsx2_colour_switcher_options''wptsx2_colourfile');

}

function 
wptsx2_colour_switcher() { ?>

<form name="colourswitcherform" action="options.php" method="post">

    <?php settings_fields('wptsx2_colour_switcher_options'); ?>
    
    <?php if($_POST['actions'] == 'update') { ?>

        <div class="updated"><p><strong>Saved!</strong></p></div>

    <?php ?>

    <div>
        <p>Please type the colour scheme stylesheet that you would like to use.<br />
        Example: <code>default-colour.css</code> or <code>blue-colour.css</code>.</p>
        <p>Below are the available colour scheme stylesheet.<br />
        You can add your own stylesheet at <code>wptsx2-theme</code> folder.</p>
        <p>The default setting is <code>default-colour.css</code></p>
        
        <ol>
        
        <?php $colourdir TEMPLATEPATH "/wptsx2-theme/";
        
$colouragent opendir($colourdir);
        
        while(
$colourfile readdir($colouragent)) {
        
            if(
is_dir($colourfile)) continue;
            
            echo 
"<li>" $colourfile ."</li>";
        
        } 
?>
        
        </ol>
                        
        <p class="submit">
            <input type="text" id="wptsx2_colourfile" name="wptsx2_colourfile" value="<?php echo get_option('wptsx2_colourfile'); ?>" /><input type="submit" class="button-primary" value="Save" />
        </p>
    </div>
    
</form>

<?php }

function 
the_colour() {

    if(
get_option('wptsx2_colourfile') == FALSE) { ?>

        <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/wptsx2-themes/default-colour.css" type="text/css" media="screen" />
    
    <?php }
    
    else { 
?>
    
        <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/wptsx2-themes/<?php echo get_option('wptsx2_colourfile'); ?>" type="text/css" media="screen" />
    
    <?php }
?>
Thank you very much.

Regards,
wgn_white
wgn_white is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to WordPress: How To Save Settings and Call That Value Again?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19286 seconds with 12 queries