Code for a widget containing all posts made over last 24 hours
3 posters
Page 1 of 1
Code for a widget containing all posts made over last 24 hours
Hi,
Please can anyone help me or point me to the right place.
I am wanting to create a widget that shows all posts made over the last 24 hours.
Any help would be very much appreciated!
Many thanks,
Alison
Edit - I am wanting the same widget as the latest topic widget, except I want it to show individual posts made in the last 24 hours.... Please does anyone have any ideas? Thanks
Please can anyone help me or point me to the right place.
I am wanting to create a widget that shows all posts made over the last 24 hours.
Any help would be very much appreciated!
Many thanks,
Alison
Edit - I am wanting the same widget as the latest topic widget, except I want it to show individual posts made in the last 24 hours.... Please does anyone have any ideas? Thanks
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Re: Code for a widget containing all posts made over last 24 hours
Bump!
Please help, our members are missing posts as the current widget only shows latest topics!!
Thanks
PS I've found this code but I'm not sure what to alter to make it work on my forum
<?php
/*
Plugin Name: Better Recent Posts Widget
Plugin URI: http://pippinsplugins.com/better-recent-posts-widget
Description: Provides a better recent posts widget, including thumbnails, category, and number options
Version: 1.1.4
Author: Pippin Williamson
Author URI: http://pippinsplugins.com
*/
/**
* Recent Posts Widget Class
*/
class pippin_recent_posts extends WP_Widget {
/** constructor */
function pippin_recent_posts() {
parent::WP_Widget(false, $name = 'Better Recent Posts');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
global $posttypes;
$title = apply_filters('widget_title', $instance['title']);
$cat = apply_filters('widget_title', $instance['cat']);
$number = apply_filters('widget_title', $instance['number']);
$offset = apply_filters('widget_title', $instance['offset']);
$thumbnail_size = apply_filters('widget_title', $instance['thumbnail_size']);
$thumbnail = $instance['thumbnail'];
$posttype = $instance['posttype'];
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>
<ul class="no-bullets">
<?php
global $post;
$tmp_post = $post;
// get the category IDs and place them in an array
$args = 'numberposts=' . $number . '&offset=' . $offset . '&post_type=' . $posttype . '&cat=' . $cat;
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li <?php if(!empty($thumbnail_size)) { $size = $thumbnail_size + 8; echo 'style="height: ' . $size . 'px;"'; } ?> >
<?php if($thumbnail == true) { ?>
<a href="<?php the_permalink(); ?>" style="float: left; margin: 0 5px 0 0;"><?php the_post_thumbnail(array($thumbnail_size));?></a>
<?php } ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br/>
<span class="time"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?></span>
</li>
<?php endforeach; ?>
<?php $post = $tmp_post; ?>
</ul>
<?php echo $after_widget; ?>
<?php
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
global $posttypes;
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['cat'] = strip_tags($new_instance['cat']);
$instance['number'] = strip_tags($new_instance['number']);
$instance['offset'] = strip_tags($new_instance['offset']);
$instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
$instance['thumbnail'] = $new_instance['thumbnail'];
$instance['posttype'] = $new_instance['posttype'];
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$posttypes = get_post_types('', 'objects');
$title = esc_attr($instance['title']);
$cat = esc_attr($instance['cat']);
$number = esc_attr($instance['number']);
$offset = esc_attr($instance['offset']);
$thumbnail_size = esc_attr($instance['thumbnail_size']);
$thumbnail = esc_attr($instance['thumbnail']);
$posttype = esc_attr($instance['posttype']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Category IDs, separated by commas'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>" type="text" value="<?php echo $cat; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number to Show:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Offset (the number of posts to skip):'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('offset'); ?>" name="<?php echo $this->get_field_name('offset'); ?>" type="text" value="<?php echo $offset; ?>" />
</p>
<p>
<input id="<?php echo $this->get_field_id('thumbnail'); ?>" name="<?php echo $this->get_field_name('thumbnail'); ?>" type="checkbox" value="1" <?php checked( '1', $thumbnail ); ?>/>
<label for="<?php echo $this->get_field_id('thumbnail'); ?>"><?php _e('Display thumbnails?'); ?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('thumbnail_size'); ?>"><?php _e('Size of the thumbnails, e.g. <em>80</em> = 80px x 80px'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>" type="text" value="<?php echo $thumbnail_size; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('posttype'); ?>"><?php _e('Choose the Post Type to display'); ?></label>
<select name="<?php echo $this->get_field_name('posttype'); ?>" id="<?php echo $this->get_field_id('posttype'); ?>" class="widefat">
<?php
foreach ($posttypes as $option) {
echo '<option value="' . $option->name . '" id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>';
}
?>
</select>
</p>
<?php
}
} // class utopian_recent_posts
// register Recent Posts widget
add_action('widgets_init', create_function('', 'return register_widget("pippin_recent_posts");'));
?>
Please help, our members are missing posts as the current widget only shows latest topics!!
Thanks
PS I've found this code but I'm not sure what to alter to make it work on my forum
<?php
/*
Plugin Name: Better Recent Posts Widget
Plugin URI: http://pippinsplugins.com/better-recent-posts-widget
Description: Provides a better recent posts widget, including thumbnails, category, and number options
Version: 1.1.4
Author: Pippin Williamson
Author URI: http://pippinsplugins.com
*/
/**
* Recent Posts Widget Class
*/
class pippin_recent_posts extends WP_Widget {
/** constructor */
function pippin_recent_posts() {
parent::WP_Widget(false, $name = 'Better Recent Posts');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
global $posttypes;
$title = apply_filters('widget_title', $instance['title']);
$cat = apply_filters('widget_title', $instance['cat']);
$number = apply_filters('widget_title', $instance['number']);
$offset = apply_filters('widget_title', $instance['offset']);
$thumbnail_size = apply_filters('widget_title', $instance['thumbnail_size']);
$thumbnail = $instance['thumbnail'];
$posttype = $instance['posttype'];
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>
<ul class="no-bullets">
<?php
global $post;
$tmp_post = $post;
// get the category IDs and place them in an array
$args = 'numberposts=' . $number . '&offset=' . $offset . '&post_type=' . $posttype . '&cat=' . $cat;
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li <?php if(!empty($thumbnail_size)) { $size = $thumbnail_size + 8; echo 'style="height: ' . $size . 'px;"'; } ?> >
<?php if($thumbnail == true) { ?>
<a href="<?php the_permalink(); ?>" style="float: left; margin: 0 5px 0 0;"><?php the_post_thumbnail(array($thumbnail_size));?></a>
<?php } ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br/>
<span class="time"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?></span>
</li>
<?php endforeach; ?>
<?php $post = $tmp_post; ?>
</ul>
<?php echo $after_widget; ?>
<?php
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
global $posttypes;
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['cat'] = strip_tags($new_instance['cat']);
$instance['number'] = strip_tags($new_instance['number']);
$instance['offset'] = strip_tags($new_instance['offset']);
$instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
$instance['thumbnail'] = $new_instance['thumbnail'];
$instance['posttype'] = $new_instance['posttype'];
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$posttypes = get_post_types('', 'objects');
$title = esc_attr($instance['title']);
$cat = esc_attr($instance['cat']);
$number = esc_attr($instance['number']);
$offset = esc_attr($instance['offset']);
$thumbnail_size = esc_attr($instance['thumbnail_size']);
$thumbnail = esc_attr($instance['thumbnail']);
$posttype = esc_attr($instance['posttype']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Category IDs, separated by commas'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>" type="text" value="<?php echo $cat; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number to Show:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Offset (the number of posts to skip):'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('offset'); ?>" name="<?php echo $this->get_field_name('offset'); ?>" type="text" value="<?php echo $offset; ?>" />
</p>
<p>
<input id="<?php echo $this->get_field_id('thumbnail'); ?>" name="<?php echo $this->get_field_name('thumbnail'); ?>" type="checkbox" value="1" <?php checked( '1', $thumbnail ); ?>/>
<label for="<?php echo $this->get_field_id('thumbnail'); ?>"><?php _e('Display thumbnails?'); ?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('thumbnail_size'); ?>"><?php _e('Size of the thumbnails, e.g. <em>80</em> = 80px x 80px'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>" type="text" value="<?php echo $thumbnail_size; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('posttype'); ?>"><?php _e('Choose the Post Type to display'); ?></label>
<select name="<?php echo $this->get_field_name('posttype'); ?>" id="<?php echo $this->get_field_id('posttype'); ?>" class="widefat">
<?php
foreach ($posttypes as $option) {
echo '<option value="' . $option->name . '" id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>';
}
?>
</select>
</p>
<?php
}
} // class utopian_recent_posts
// register Recent Posts widget
add_action('widgets_init', create_function('', 'return register_widget("pippin_recent_posts");'));
?>
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Re: Code for a widget containing all posts made over last 24 hours
Do you use phpBB2, please provide your forum url.
Guest- Guest
Re: Code for a widget containing all posts made over last 24 hours
Hi,
Yes sorry I do use phpBB2 and my forum addy is americandayvans.com
Thanks
Yes sorry I do use phpBB2 and my forum addy is americandayvans.com
Thanks
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Re: Code for a widget containing all posts made over last 24 hours
That code doesn't work on forumotion, PHP is not allowed.
Guest- Guest
Re: Code for a widget containing all posts made over last 24 hours
Thanks for your help. How about this code then? Or should I just give up? lol
<div style="background: none repeat scroll 0 0 ##ffffff;
border: 0.0em solid #1177AA;
color: #222222;
font-family: HelveticaNeue,Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 700;
line-height: 20px;
padding: 0 3px 0 8px;
text-decoration: none;
vertical-align: baseline;
width: 150px;;">
<h2>Under Construction</h2>
<ul style="">
<?php
$args = array( 'numberposts' => 15, 'category' => 12345 );
$cat_posts = get_posts( $args );
foreach( $cat_posts as $post ) : setup_postdata($post); ?>
<li><a style=" font-size: 12px; font-weight:bold; text-decoration: none;" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<ol style=" font-size: 10px; font-weight:bold; color:#CC0000; text-transform: uppercase;"><?php the_date(); ?> | Author : <?php the_author(); ?> | <?php comments_number('no responses','one response','% responses'); ?></ol>
</li>
<?php endforeach; ?>
</ul>
</div>
<div style="background: none repeat scroll 0 0 ##ffffff;
border: 0.0em solid #1177AA;
color: #222222;
font-family: HelveticaNeue,Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 700;
line-height: 20px;
padding: 0 3px 0 8px;
text-decoration: none;
vertical-align: baseline;
width: 150px;;">
<h2>Under Construction</h2>
<ul style="">
<?php
$args = array( 'numberposts' => 15, 'category' => 12345 );
$cat_posts = get_posts( $args );
foreach( $cat_posts as $post ) : setup_postdata($post); ?>
<li><a style=" font-size: 12px; font-weight:bold; text-decoration: none;" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<ol style=" font-size: 10px; font-weight:bold; color:#CC0000; text-transform: uppercase;"><?php the_date(); ?> | Author : <?php the_author(); ?> | <?php comments_number('no responses','one response','% responses'); ?></ol>
</li>
<?php endforeach; ?>
</ul>
</div>
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Re: Code for a widget containing all posts made over last 24 hours
Or.... just a thought... can I override the recent topics widget to display posts instead?
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Re: Code for a widget containing all posts made over last 24 hours
Please avoid double/triple posting. Posts need to be separated by 24 hours before bumping, replying or adding more information. Please use the edit button. |
Jophy- ForumGuru
- Posts : 17922
Reputation : 836
Language : English
Location : Somewhere
Re: Code for a widget containing all posts made over last 24 hours
Hi,
The code you found is PHP and it won't work on Forumotion. I don't think you can display topics for last 24 hours. However, you can somehow show topics since user's last visit or unanswered topics.
You can use javascript for that if you know it.
The code you found is PHP and it won't work on Forumotion. I don't think you can display topics for last 24 hours. However, you can somehow show topics since user's last visit or unanswered topics.
You can use javascript for that if you know it.
ankillien- Energetic
- Posts : 5198
Reputation : 129
Language : English, XHTML, CSS, JS, PHP, SQL
Re: Code for a widget containing all posts made over last 24 hours
This will display a list of new topics here, from the past 24 hours:
https://help.forumotion.com/search?search_keywords=&search_author=*&search_time=1
That, plus some javascript, will get the OP what he wants.
As would having his members use the Notify and Favorites features.
https://help.forumotion.com/search?search_keywords=&search_author=*&search_time=1
That, plus some javascript, will get the OP what he wants.
As would having his members use the Notify and Favorites features.
Guest- Guest
Re: Code for a widget containing all posts made over last 24 hours
Oh yeah! Advanced search has this ability
ankillien- Energetic
- Posts : 5198
Reputation : 129
Language : English, XHTML, CSS, JS, PHP, SQL
Re: Code for a widget containing all posts made over last 24 hours
Ok, thanks everyone. Sorry, I'm still learning.
ali-phant- Forumember
- Posts : 27
Reputation : 1
Language : english
Location : England
Jophy- ForumGuru
- Posts : 17922
Reputation : 836
Language : English
Location : Somewhere
Similar topics
» Widget Made My Site Inaccessible
» How to do this Advanced Hiding Widget Code as well as the Recent Topic's Widget Modification
» New Widget Code
» Widget code help please.
» How can I restrict access to certain threads unless member has made several posts?
» How to do this Advanced Hiding Widget Code as well as the Recent Topic's Widget Modification
» New Widget Code
» Widget code help please.
» How can I restrict access to certain threads unless member has made several posts?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum