Hallo alle zusammen,
ich habe hier ein plugin gefunden welches so in etwa meinen vorstellungen entspricht mit dem ich ein random link in meinen posts anzeigen lassen kann. Allerdings zeigt er mir stat der link namen ein button an. Kann man das plugin irgendwie so ändern das mir direkt der link angezeigt wird, also zb
(Das hier ist ein Link) das er also den link text auch aus der besagten kategorie nimmt?! Müsste doch machbar sein oder? Ich hoffe das ihr mir weiterhelfen könnt. vielen dank für eure hilfe! ;)
Das plugin als code:
PHP
<?php
/*
Plugin Name: Random Link Button
Plugin URI: http://www.u-g-h.com/?page_id=114
Description: Adds a new function which picks a link at random from a specified category. Usage: Add the term <code><?php randomlinkbutton(); ?></code> to your template where you wish the RandomLinkButton to appear, or if you use widgets, the button will appear automatically in your widget window.
Version: 0.5
Author: Owen Cutajar
Author URI: http://www.u-g-h.com
*/
/* History:
v0.1 - OwenC - Created base version
v0.2 - jnicholi (http://www.jnicholi.com) - Turned into a widget
v0.3 - OwenC - Added support for both widget and non-widget users
v0.4 - jnicholi & OwenC - Added category support + open in different window option
v0.5 - OwenC - Upgraded to WordPress 2.1 compliance
*/
function widget_randomlinkbutton_init() {
if ( !function_exists('register_sidebar_widget') )
return;
function widget_randomlinkbutton($args) {
extract($args);
$options = get_option('randomlinkbutton');
$title = $options['title'];
$category = $options['category'];
$image = $options['image'];
$target = $options['target'];
echo $before_widget . $before_title . $title . $after_title;
docommon_randomlinkbutton ( $category , $image , $target );
echo $after_widget;
}
function widget_randomlinkbutton_control() {
global $wpdb;
$options = get_option('randomlinkbutton');
if ( !is_array($options) )
// Set cat to 1 as default
$options = array( 'title'=>'Random Links', 'category'=>'', 'image'=>'/randombutton.jpg', 'target'=>'');
if ( $_POST['randomlink-submit'] ) {
// Change sidebar title
$options['title'] = strip_tags(stripslashes($_POST['randomlink-title']));
$options['category'] = strip_tags(stripslashes($_POST['randomlink-category']));
$options['image'] = strip_tags(stripslashes($_POST['randomlink-image']));
$options['target'] = strip_tags(stripslashes($_POST['randomlink-target']));
update_option('randomlinkbutton', $options);
}
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$category = htmlspecialchars($options['category'], ENT_QUOTES);
$image = htmlspecialchars($options['image'], ENT_QUOTES);
$target = htmlspecialchars($options['target'], ENT_QUOTES);
// Get category list to display in widget control panel
$results = get_categories("type=link");
echo '<p style="text-align:right;"><label for="randomlink-title">' . __('Title:') . ' <input style="width: 200px;" id="randomlink-title" name="randomlink-title" type="text" value="'.$title.'" /></label></p>';
echo '<p style="text-align:right;"><label for="randomlink-image">' . __('Image Location:') . ' <input style="width: 200px;" id="randomlink-image" name="randomlink-image" type="text" value="'.$image.'" /></label></p>';
// Display categories available as a drop down menu
echo '<p style="text-align:center;"><label for="randomlink-category">' . __('Category:') . ' <select id="randomlink-category" name="randomlink-category">';
foreach ($results as $result) {
echo '<option value="'.$result->link_category.'">'.$result->link_category.': '.$result->cat_name.'</option>';
}
echo '</select></p>';
// end category menu
echo '<p style="text-align:center;"><label for="randomlink-target">' . __('Target:') . ' <select id="randomlink-target" name="randomlink-target">';
echo '<option value="" >Open link in the same window</option>';
echo '<option value="new">Open link in a new window</option>';
echo '</select></p>';
echo '<input type="hidden" id="randomlink-submit" name="randomlink-submit" value="1" />';
}
register_sidebar_widget(array('Random Link', 'widgets'), 'widget_randomlinkbutton');
register_widget_control(array('Random Link', 'widgets'), 'widget_randomlinkbutton_control', 300, 130);
;
}
function randomlinkbutton(){
$options = get_option('randomlinkbutton');
$title = $options['title'];
$category = $options['category'];
$image = $options['image'];
$target = $options['target'];
docommon_randomlinkbutton ( $category, $image, $target );
}
function docommon_randomlinkbutton( $category = 0 , $image = "/randombutton.jpg" , $target = '') {
global $wpdb;
$results = get_bookmarks("category=$category&orderby=rand&limit=1");
// loop caters for 0 results (no image) or multiple results (which shouldn't happen)
foreach ($results as $result) {
// fill out variables from database
$link_url = $result->link_url;
$link_name = $result->link_name;
echo '<a href="'.$link_url.'" title="'.$link_name.'"';
if ($target == 'new') echo ' target="_blank"';
echo '><img border="0" src="'.$image.'" class="randombutton"></a>';
}
}
function randomlinkbutton_options() {
// Note: Options for this plugin include a "Title" setting which is only used by the widget
$options = get_option('randomlinkbutton');
//set initial values if none exist
if ( !is_array($options) ) {
$options = array( 'title'=>'Random Links', 'category'=>'', 'image'=>'/randombutton.jpg', 'target'=>'');
}
if ( $_POST['randomlink-submit'] ) {
$options['category'] = strip_tags(stripslashes($_POST['randomlink-category']));
$options['image'] = strip_tags(stripslashes($_POST['randomlink-image']));
$options['target'] = strip_tags(stripslashes($_POST['randomlink-target']));
update_option('randomlinkbutton', $options);
}
$category = htmlspecialchars($options['category'], ENT_QUOTES);
$image = htmlspecialchars($options['image'], ENT_QUOTES);
$target = htmlspecialchars($options['target'], ENT_QUOTES);
// Get category list to display in drop down list
$cats = get_categories("type=link");
?>
<div class="wrap">
<h2><?php _e('Contact Form Options') ?></h2>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=randomlinkbutton.php">
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top">
<th scope="row"><?php _e('Image Location:') ?></th>
<td><input name="randomlink-image" type="text" id="randomlink-image" value="<?php echo $image; ?>" size="80" />
<br />
<?php _e('Enter the location of an image for the random button. For example, if the image is in the root of your website and called randomimage.jpg, use "/randomimage.jpg" ') ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Category:') ?></th>
<td>
<select id="randomlink-category" name="randomlink-category">
<option value=""><< All Categories >></option>
<?php
foreach ($cats as $cat) {
echo '<option value="'.$cat->cat_ID.'"';
if ($cat->cat_ID == $category)
echo ' selected ';
echo '>'.$cat->cat_ID.': '.$cat->cat_name;
echo '</option>';
} ?>
</select>
<br />
<?php _e('Specify the category to select a link from.') ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Target:') ?></th>
<td>
<select id="randomlink-target" name="randomlink-target">
<option value="" <?php if ($target=='') echo 'selected'; ?>>Open link in the same window</option>
<option value="new" <?php if ($target=='new') echo 'selected'; ?>>Open link in a new window</option>
</select>
<br />
<?php _e('Choose whether you would like the link to open in the same window or a new window ') ?></td>
</tr>
</table>
<input type="hidden" id="randomlink-submit" name="randomlink-submit" value="1" />
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update Options') ?> »" />
</p>
</form>
</div>
<?php
}
function randomlinkbutton_adminmenu(){
if (function_exists('add_options_page')) {
add_options_page('Random Link Button Options', 'Random Link Button', 9, 'randomlinkbutton.php', 'randomlinkbutton_options');
}
}
add_action('widgets_init', 'widget_randomlinkbutton_init');
add_action('admin_menu','randomlinkbutton_adminmenu',1);
?>
Alles anzeigen
Link zur plugin homepage: Klicke Hier
MfG Hannes