Social options

In acest tutorial vreau sa va arat cu poti sa faci la o tema wordpress in dashboard optiuni in panou pentru iconitele de social facebook,twitter,google plus.

Avem acest cod care se pune in functions.php

[codesyntax lang=”php” container=”div” blockstate=”expanded”]

/* Social Options in wp-admin */

add_action('admin_menu', 'thesis_custom_add_page'); // Moves the add page function in the WP dashboard admin menu via WP hook
function thesis_custom_add_page() { // Adds our test page to Thesis menu
add_submenu_page('thesis-options',__('More Options', 'ebox'), __('More Options', 'ebox'), 'edit_themes', 'more-options', 'more_options_admin');
add_theme_page('Social Options', 'Social Options', 'edit_themes', 'more-options', 'more_options_admin');
function more_options_admin() { // Our function (as seen above) that runs when the page is accessed
$tt_hidden_field_name = 'tt_submit_hidden';
$tt_twitter_option = 'tt_twitter_name'; // Option name (in db)
$tt_data_field_name = 'tt_twitter_field';

$gg_googleplus_option = 'gg_googleplus_name'; // Option name (in db)
$gg_data_field_name = 'gg_googleplus_field';

$fa_facebook_option = 'fa_facebook_name';
$fa_data_field_name = 'fa_facebook_field';

$tt_twitter_value = get_option($tt_twitter_option); // Read in existing option value from database
$fa_facebook_value = get_option($fa_facebook_option);
$gg_googleplus_value = get_option($gg_googleplus_option);

if( $_POST[ $tt_hidden_field_name ] == 'yes' ) { // If form has been sumbitted
$tt_twitter_value = $_POST[ $tt_data_field_name ]; // Read value from post
$fa_facebook_value = $_POST[ $fa_data_field_name ];
$gg_googleplus_value = $_POST[ $gg_data_field_name ];

update_option($tt_twitter_option, $tt_twitter_value); // Save value in database
update_option($fa_facebook_option, $fa_facebook_value);
update_option($gg_googleplus_option, $gg_googleplus_value);
<div><p><strong>Your changes have been saved !</strong></p></div>

// Main screen:
echo '<div>';
echo "<h2>Social Options</h2>"; // header
<div class="screen" style="width:700px;float:left;padding:40px;border:3px double #ccc;background:#EEEEEE;box-shadow:0 10px 12px -8px #777;">
<form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="<?php echo $tt_hidden_field_name; ?>" value="yes">
<p>Twitter username:
<input type="text" name="<?php echo $tt_data_field_name; ?>" value="<?php echo $tt_twitter_value; ?>" size="25">

<p>Facebook URL :  http://
<input type="text" name="<?php echo $fa_data_field_name; ?>" value="<?php echo $fa_facebook_value;?>" size="25">

<p>Google plus URL : http://  
<input type="text" name="<?php echo $gg_data_field_name; ?>" value="<?php echo $gg_googleplus_value;?>" size="25">

<p><input type="submit" name="search" value="<?php _e('Saves the settings', 'ebox'); ?>" class="btn button-primary" style="text-shadow:none;" /></p>



Dupa introducerea acestui cod se poate vedea cu apare in meniu.

Pentru ca sa se si vada in tema noastra eu le-am pus in single.php dar se pot pune oriunde doreste fiecare header,footer,sidebar.

[codesyntax lang=”php” container=”div” blockstate=”expanded”]

<div id="social" style="width:300px;float:left;height:40px;">
$twitter = get_option('tt_twitter_name');
$facebook = get_option('fa_facebook_name');
$googleplus = get_option('gg_googleplus_name');
<p align="center"><?php if($twitter){?><a href="<?php echo $twitter;?>"><img src="<?php bloginfo('template_url');?>/images/twitter.png" /></a><?php } if($facebook){?> <a href="http://<?php echo $facebook;?>"><img src="<?php bloginfo('template_url');?>/images/facebook.png" /></a>
<?php } if($googleplus){?> <a href="http://<?php echo $googleplus;?>"><img src="<?php bloginfo('template_url');?>/images/google.png" /></a>
<?php } ?></p>


Ce mai trebuie complectat sunt trei poze intr-un folder in tema numit images cu facebook.png,google.png si twitter.png.

3 thoughts on “Social options

Comments are closed.