-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
A year of web hosting for Managed WordPress on Hostinger is now 91% off
By News Staff,
- hostinger
- web hosting
- (and 4 more)
- 0 replies
- 0 views
-
[Deal Alert] 1-Year subscription to Hostinger Web Hosting for Managed WordPress now 91% off
By News Staff,
- 0 replies
- 0 views
-
WordPress 6.9 BETA 1 is out now - the community is invited to test the new version -...
By thedhubs,
- 0 answers
- 629 views
-
WordPress-Theme Twenty Twenty Four-customizing: how to do that - a Gutenberg special question...
By thedhubs,
- 2 answers
- 3202 views
-
Nothing's community widget brings classic 'Snake' game to your phone's home screen
By Sagar Naresh,
- nothing
- nothing widget
- (and 4 more)
- 0 replies
- 2 views
-
Question
hooko22
Hey there guys.
Ok thing is I really suck at php and I'm trying to exlude a post, or possible a category, either one would work, from a random post widget I have.
If you check out the site you can see the widget on the right side (random paranormal movies) is displaying my sticky welcome message at the top.
I know the category id and post id and have tried a few things to no avail.
Anyway any help would sure be welcome:
<?php
/*
Plugin Name: Simple Random Posts Widget
Plugin URI: http://infobak.nl/si...for-wordpress//
Version: 1.26
Description: Widget which displays random posts
Author: Jan Meeuwesen
Author URI: http://infobak.nl/si...-for-wordpress/
License: GPLv2
Copyright 2012 Jan Meeuwesen
*/
define("DefNoOfPosts", "5"); // default number of random posts to display
class SimpleRandomPostsWidget extends WP_Widget {
function SimpleRandomPostsWidget()
{
parent::WP_Widget( false, 'Simple Random Posts', array('description' => 'Random posts widget') );
}
function widget($args, $instance)
{
global $NewSimpleRandomPosts;
$title = empty( $instance['title'] ) ? 'Simple Random Posts' : $instance['title'];
echo $args['before_widget'];
echo $args['before_title'] . $title . $args['after_title'];
echo $NewSimpleRandomPosts->GetSimpleRandomPosts( empty( $instance['ShowPosts'] ) ? DefNoOfPosts : $instance['ShowPosts'] );
echo $args['after_widget'];
}
function update($new_instance)
{
return $new_instance;
}
function form($instance)
{
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Title:'; ?></label>
<input type="text" name="<?php echo $this->get_field_name('title'); ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('ShowPosts'); ?>"><?php echo 'Number of entries:'; ?></label>
<input type="text" name="<?php echo $this->get_field_name('ShowPosts'); ?>" id="<?php echo $this->get_field_id('ShowPosts'); ?>" value="<?php if ( empty( $instance['ShowPosts'] ) ) { echo esc_attr(DefNoOfPosts); } else { echo esc_attr($instance['ShowPosts']); } ?>" size="3" />
</p>
<?php
}
}
class SimpleRandomPosts {
function GetSimpleRandomPosts($noofposts)
{
rewind_posts();
query_posts('orderby=rand&showposts='.$noofposts);
if (have_posts()) :
echo '<ul>';
while (have_posts()) : the_post();
echo '<div id="post-'.get_the_ID().'"><li><a href="'.get_permalink().'">'.get_the_title().'</a></li></div>';
endwhile;
echo '</ul>';
endif;
wp_reset_query();
}
}
$NewSimpleRandomPosts = new SimpleRandomPosts();
function SimpleRandomPosts_widgets_init()
{
register_widget('SimpleRandomPostsWidget');
}
add_action('widgets_init', 'SimpleRandomPosts_widgets_init');
?>
Link to comment
https://www.neowin.net/forum/topic/1125590-excluding-post-or-category-from-random-post-widget/Share on other sites
8 answers to this question
Recommended Posts