Function.php
<?php
function the_title2($before = '', $after = '', $echo = true, $length = false) {
$title = get_the_title();
if ( $length && is_numeric($length) ) {
$title = substr( $title, 0, $length );
}
if ( strlen($title)> 0 ) {
$title = apply_filters('the_title2', $before . $title . $after, $before, $after);
if ( $echo )
echo $title;
else
return $title;
}
}
?>
<?php
$new_meta_boxes =
array(
"image" => array(
"name" => "image",
"std" => "",
"title" => "Thumbnail Image",
"description" => "Place the full path your your image here to have it displayed as a thumbnail")
);
function new_meta_boxes() {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);
if($meta_box_value == "")
$meta_box_value = $meta_box['std'];
echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
echo'<h2>'.$meta_box['title'].'</h2>';
echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" size="55" /><br />';
echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';
}
}
function create_meta_box() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'new-meta-boxes', 'eGamer Thumbnail Settings', 'new_meta_boxes', 'post', 'normal', 'high' );
}
}
function save_postdata( $post_id ) {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
// Verify
if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ))
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
}
$data = $_POST[$meta_box['name'].'_value'];
if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
update_post_meta($post_id, $meta_box['name'].'_value', $data);
elseif($data == "")
delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
}
}
add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="sidebar-box">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?>
<?php
$themename = "eGamer Theme";
$shortname = "artsee";
$options = array (
array( "name" => "Layout Settings",
"type" => "titles",),
array( "name" => "<span style='float: left;'>Post Format</span>",
"id" => $shortname."_format",
"type" => "select",
"std" => "Default",
"options" => array("Default", "Blog Style")),
array( "name" => "Homepage Options",
"type" => "titles"),
array( "name" => "Hide/Display Recent Video",
"id" => $shortname."_video",
"type" => "select",
"std" => "Hide",
"options" => array("Display", "Hide")),
array( "name" => "Hide/Display son Reviews",
"id" => $shortname."_rating",
"type" => "select",
"std" => "Hide",
"options" => array("Display", "Hide")),
array( "name" => "Hide/Display Random/Popular Articles",
"id" => $shortname."_popular",
"type" => "select",
"std" => "Display",
"options" => array("Display", "Hide")),
array( "name" => "Number of Recent-Posts Displayed on Homepage",
"id" => $shortname."_homepage_posts",
"std" => "6",
"type" => "text"),
array( "name" => "Number of Featured-Posts Displayed on Homepage",
"id" => $shortname."_homepage_featured",
"std" => "3",
"type" => "text"),
array( "name" => "Post-Page Options",
"type" => "titles"),
array( "name" => "<span style='float: left;'>Hid/Display Thumbnails on Post Pages</span>",
"id" => $shortname."_thumbnails",
"type" => "select",
"std" => "Display",
"options" => array("Display", "Hide")),
array( "name" => "<span style='float: left;'>Hid/Display Tabbed Menu</span>",
"id" => $shortname."_posttabs",
"type" => "select",
"std" => "Display",
"options" => array("Display", "Hide")),
array( "name" => "<span style='float: left;'>Comments Style</span>",
"id" => $shortname."_comments",
"type" => "select",
"std" => "Graphical",
"options" => array("Graphical", "Minimal")),
array( "name" => "Navigation Options",
"type" => "titles"),
array( "name" => "Exclude Pages From Navigation by ID (separate by ',')",
"id" => $shortname."_exclude_page",
"std" => "",
"type" => "text"),
array( "name" => "Exclude Categories From Navigation by ID (separate by ',')",
"id" => $shortname."_exclude_cat",
"std" => "",
"type" => "text"),
array( "name" => "Sort Categorie Links by Name/ID",
"id" => $shortname."_sort_cat",
"type" => "select",
"std" => "name",
"options" => array("name", "ID")),
array( "name" => "Order Category Links by Ascending/Descending",
"id" => $shortname."_order_cat",
"type" => "select",
"std" => "asc",
"options" => array("asc", "desc")),
array( "name" => "Order Pages Links by Ascending/Descending",
"id" => $shortname."_order_page",
"type" => "select",
"std" => "asc",
"options" => array("asc", "desc")),
array( "name" => "Advertisement Options",
"type" => "titles"),
array( "name" => "Enable/Disable 125x125 Sidebar Ads",
"id" => $shortname."_ads",
"type" => "select",
"std" => "Disable",
"options" => array("Disable", "Enable")),
array( "name" => "Enable/Disable 468x60 Advertisement (on post pages)",
"id" => $shortname."_foursixeight",
"type" => "select",
"std" => "Disable",
"options" => array("Disable", "Enable")),
array( "name" => "Banner Management",
"type" => "titles"),
array( "name" => "468x60 Banner Image",
"id" => $shortname."_banner_468",
"std" => "http://www.elegantwordpressthemes.com/images/eGamer/468x60.gif",
"type" => "text"),
array( "name" => "468x60 Banner URL",
"id" => $shortname."_banner_468_url",
"std" => "#",
"type" => "text"),
array( "name" => "125x125 Banner #1 Image",
"id" => $shortname."_banner_image_one",
"std" => "http://www.elegantwordpressthemes.com/images/eGamer/125x125.gif",
"type" => "text"),
array( "name" => "125x125 Banner #1 URL",
"id" => $shortname."_banner_url_one",
"std" => "#",
"type" => "text"),
array( "name" => "125x125 Banner #2 Image",
"id" => $shortname."_banner_image_two",
"std" => "http://www.elegantwordpressthemes.com/images/eGamer/125x125.gif",
"type" => "text"),
array( "name" => "125x125 Banner #2 URL",
"id" => $shortname."_banner_url_two",
"std" => "#",
"type" => "text"),
array( "name" => "125x125 Banner #3 Image",
"id" => $shortname."_banner_image_three",
"std" => "http://www.elegantwordpressthemes.com/images/eGamer/125x125.gif",
"type" => "text"),
array( "name" => "125x125 Banner #3 URL",
"id" => $shortname."_banner_url_three",
"std" => "#",
"type" => "text"),
array( "name" => "125x125 Banner #4 Image",
"id" => $shortname."_banner_image_four",
"std" => "http://www.elegantwordpressthemes.com/images/eGamer/125x125.gif",
"type" => "text"),
array( "name" => "125x125 Banner #4 URL",
"id" => $shortname."_banner_url_four",
"std" => "#",
"type" => "text"),
);
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($options as $value) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $value['id'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "Current Theme Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}
function mytheme_admin() {
global $themename, $shortname, $options;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
?>
<div class="wrap">
<h2><?php echo $themename; ?> settings</h2>
<form method="post">
<?php foreach ($options as $value) {
if ($value['type'] == "text") { ?>
<div style="float: left; width: 880px; background-color:#E4F2FD; border-left: 1px solid #C2D6E6; border-right: 1px solid #C2D6E6; border-bottom: 1px solid #C2D6E6; padding: 10px;">
<div style="width: 200px; float: left;"><?php echo $value['name']; ?></div>
<div style="width: 680px; float: left;"><input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width: 400px;" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></div>
</div>
<?php } elseif ($value['type'] == "text2") { ?>
<div style="float: left; width: 880px; background-color:#E4F2FD; border-left: 1px solid #C2D6E6; border-right: 1px solid #C2D6E6; border-bottom: 1px solid #C2D6E6; padding: 10px;">
<div style="width: 200px; float: left;"><?php echo $value['name']; ?></div>
<div style="width: 680px; float: left;"><textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width: 400px; height: 200px;" type="<?php echo $value['type']; ?>"><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></div>
</div>
<?php } elseif ($value['type'] == "select") { ?>
<div style="float: left; width: 880px; background-color:#E4F2FD; border-left: 1px solid #C2D6E6; border-right: 1px solid #C2D6E6; border-bottom: 1px solid #C2D6E6; padding: 10px;">
<div style="width: 200px; float: left;"><?php echo $value['name']; ?></div>
<div style="width: 680px; float: left;"><select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width: 400px;">
<?php foreach ($value['options'] as $option) { ?>
<option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
<?php } ?>
</select></div>
</div>
<?php } elseif ($value['type'] == "titles") { ?>
<div style="float: left; width: 870px; padding: 15px; background-color:#2583AD; border: 1px solid #2583AD; color: #FFF; font-size: 16px; font-weight: bold; margin-top: 25px;">
<?php echo $value['name']; ?>
</div>
<?php
}
}
?>
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
<?php
}
function mytheme_wp_head() { ?>
<?php }
add_action('wp_head', 'mytheme_wp_head');
add_action('admin_menu', 'mytheme_add_admin'); ?>
<?php
$new_meta_boxes2 =
array(
"image" => array(
"name" => "rating",
"std" => "",
"title" => "Assign a Rating",
"description" => "Place the full path your your image here to have it displayed as a thumbnail")
);
function new_meta_boxes2() {
global $post, $new_meta_boxes2;
foreach($new_meta_boxes2 as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);
if($meta_box_value == "")
$meta_box_value = $meta_box['std'];
echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
echo'<h2>'.$meta_box['title'].'</h2>';
echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" size="55" /><br />';
echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';
}
}
function create_meta_box2() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'new-meta-boxes2', 'eGamer Rating Settings', 'new_meta_boxes2', 'post', 'normal', 'high' );
}
}
function save_postdata2( $post_id ) {
global $post, $new_meta_boxes2;
foreach($new_meta_boxes2 as $meta_box) {
// Verify
if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ))
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
}
$data = $_POST[$meta_box['name'].'_value'];
if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
update_post_meta($post_id, $meta_box['name'].'_value', $data);
elseif($data == "")
delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
}
}
add_action('admin_menu', 'create_meta_box2');
add_action('save_post', 'save_postdata2');
?>