Search
Syndication
Sponsors

Archive for the ‘Wordpress’ Category

Shortcode example

Sunday, February 14th, 2010

{
return 'hello world';
// or echo
}
?>

Then add [helloworld] to the post.

Dynamic Title In Wordpress

Tuesday, June 9th, 2009

<title>
<?phpif (is_home())
{
echo bloginfo(’name’);
}
elseif (is_404())
{
echo ‘404 Not Found’;
}
elseif (is_category())
{
echo ‘Category:’; wp_title(”);
}
elseif (is_search())
{
echo ‘Search Results’;
}
elseif ( is_day() || is_month() || is_year() )
{
echo ‘Archives:’; wp_title(”);
}
else
{
echo wp_title(”);
}
?>
</title>

Lottery Widget Source Code

Wednesday, February 4th, 2009

This is a simple widget example which generates some lottery numbers (UK) and displays them in the sidebar.

<?php
/*
Plugin Name: UK lottery numbers
Plugin URI: http://www.getphp.net
Description: Generate numbers for the UK lottery
Author: shedboy
Version: 0.1
Author URI: http://www.getphp.net

Change History
0.1 : First version displays 6 numbers between 1 and 49

*/

//Lottery function, generates 6 random numbers between 1 and 49
function lottery($maxn = “49″,$maxb=”6″)
{
srand((double) microtime() * 1000000);
while (1>0)
{
$lottery[] = rand(1,$maxn);
$lottery = array_unique($lottery);
if (sizeof($lottery) == $maxb) break;
}
sort($lottery);
return implode(”, “,$lottery);
}
function widget_uklottery_init()
{

if ( !function_exists(’register_sidebar_widget’))
return;
 
 function widget_uklottery()
 {
  # this  prints the widget
  echo $before_widget;
  echo $before_title;
  
  $lotterynums = lottery();
  echo “<h2>UK Lottery numbers generator</h2>”;
  echo “<br>$lotterynums<br><br><br>”;

  echo $after_title;
  echo $after_widget;
 }

register_sidebar_widget(’UK lottery Widget’, ‘widget_uklottery’);
}

add_action(’widgets_init’, ‘widget_uklottery_init’);
?>

Amazon UK Wordpress Plugin Source Code

Wednesday, February 4th, 2009

Similar to the AMazon.com version, this was for the UK site but they dropped the ad support

<?php
/*
Plugin Name: amazon uk contextual ads
Plugin URI:
Description: This plugin adds the amazon contextual ads code to your blog
Version: 0.1
Author: IH
Author URI: http://www.getphp.net
*/

// This function outputs the amazon javascript for the configured user
function amazonuk_output()
{
    // get the publisher id
    $amazonuk_id = get_option(’amazonuk_id’);
    ?>
 <!– start of amazon uk context links code –>
<script type=”text/javascript”><!–
 amzn_cl_tag=”<?php echo $amazonuk_id ?>”;
 amzn_cl_link_color=”0000FF”;
 amzn_cl_max_links=12;
 amzn_cl_link_style=3;
//–></script>
<script type=”text/javascript” src=”http://cls.assoc-amazon.co.uk/gb/s/cls.js”></script>
    <!– end of amazon uk context links code –>
<?php
}

// Adds the amazon settings menu to the Wordpress options page
function amazonuk_menu()
{
    add_options_page(’Amazon UK Settings’, ‘Amazon UK Settings’, 8, __FILE__, ‘amazonuk_options’);
}

// Output the options menu page
function amazonuk_options()
{
    ?>
    <div class=”wrap”>
    <h2>Amazon UK Settings </h2>

 <form method=”post” action=”">
 <?php wp_nonce_field(’update-options’); ?>
 <p class=”submit”>
 <input type=”submit” name=”Submit” value=”<?php _e(’Update Options »’) ?>” />
 </p>

 <?php
     echo ‘<table>’;
     $parameters = array
  (
     ‘amazonuk_id’ => ‘Amazon UK publisher ID’,
     );

     if ($_POST['action'] == ‘update’)
  {
  foreach($parameters as $param => $desc)
  {
      update_option($param, $_POST[$param]);
  }
     }
    
     foreach($parameters as $param => $desc){
  echo “<tr><td> $desc: </td> <td> <input type=’text’ name=’$param’ value=’”.get_option($param).”‘ /> </td></tr>”;
     }
     echo ‘</table>’;
     $page_options = implode(’,', array_keys($parameters));
 ?>
 
 <input type=”hidden” name=”page_options” value=”<?php echo $page_options ?>” />
 <input type=”hidden” name=”action” value=”update” />

 <p class=”submit”>
 <input type=”submit” name=”Submit” value=”<?php _e(’Update Options »’) ?>” />
 </p>
 </form>
    </div>
    <?php
}

add_option(’amazonuk_id’, ‘xxxxxxxxxxxx’);
add_action(’admin_menu’, ‘amazonuk_menu’);
add_action(’wp_footer’, ‘amazonuk_output’);
?>

Amazon Wordpress Plugin code

Wednesday, February 4th, 2009

This was a plugin that was quickly thrown up to use Amazon in links, Amazon appears to have removed this form of advertising but the code is posted here because it may help a new wordpress developer on the road to start developing simple plugins.

 

<?php
/*
Plugin Name: amazon contextual ads
Plugin URI: http://www.getphp.net
Description: This plugin adds the amazon contextual ads code to your blog
Version: 0.1
Author: IH
Author URI: http://www.getphp.net
*/

// This function outputs the amazon javascript for the configured user
function amazon_output()
{
    // get the publisher id
    $amazon_id = get_option(’amazon_id’);
    ?>
 <!– start of amazon context links code –>
<script type=”text/javascript”><!–
 amzn_cl_tag=”<?php echo $amazon_id ?>”;
 amzn_cl_link_color=”0000FF”;
 amzn_cl_max_links=20;
 amzn_cl_link_style=3;
 amzn_cl_logo=0;
//–></script>
<script type=”text/javascript” src=”http://cls.assoc-amazon.com/s/cls.js”></script>
    <!– end of amazon context links code –>
<?php
}

// Adds the amazon settings menu to the Wordpress options page
function amazon_menu()
{
    add_options_page(’amazon Settings’, ‘amazon Settings’, 8, __FILE__, ‘amazon_options’);
}

// Output the options menu page
function amazon_options()
{
    ?>
    <div class=”wrap”>
    <h2>Amazon Settings </h2>

 <form method=”post” action=”">
 <?php wp_nonce_field(’update-options’); ?>
 <p class=”submit”>
 <input type=”submit” name=”Submit” value=”<?php _e(’Update Options »’) ?>” />
 </p>

 <?php
     echo ‘<table>’;
     $parameters = array
  (
     ‘amazon_id’ => ‘amazon publisher ID’,
     );

     if ($_POST['action'] == ‘update’)
  {
  foreach($parameters as $param => $desc)
  {
      update_option($param, $_POST[$param]);
  }
     }
    
     foreach($parameters as $param => $desc){
  echo “<tr><td> $desc: </td> <td> <input type=’text’ name=’$param’ value=’”.get_option($param).”‘ /> </td></tr>”;
     }
     echo ‘</table>’;
     $page_options = implode(’,', array_keys($parameters));
 ?>
 
 <input type=”hidden” name=”page_options” value=”<?php echo $page_options ?>” />
 <input type=”hidden” name=”action” value=”update” />

 <p class=”submit”>
 <input type=”submit” name=”Submit” value=”<?php _e(’Update Options »’) ?>” />
 </p>
 </form>
    </div>
    <?php
}

add_option(’amazon_id’, ‘xxxxxxxxxxxx’);
add_action(’admin_menu’, ‘amazon_menu’);
add_action(’wp_footer’, ‘amazon_output’);
?>