| Server IP : 27.254.66.5 / Your IP : 216.73.217.39 Web Server : Apache/2 System : Linux cs82.hostneverdie.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64 User : technic2 ( 1951) PHP Version : 7.4.30 Disable Function : apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd,exec, fp, fput, highlight_file, ini_alter, ini_restore, inject_code, passthru,phpAds_remoteInfo, phpAds_XmlRpc,phpAds_xmlrpcDecode, phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid,posix_setuid, posix_setuid, posix_uname,proc_open,proc_close, proc_get_status, proc_nice, proc_terminate, shell_exec, syslog, system, xmlrpc_entity_decode, show_source,sleep,pcntl_exec,virtual,suexec,dbmopen,dl,symlink,disk_free_space,diskfreespace,leak MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/technic2/public_html/old-website/wp-content/themes/synapse/framework/widgets/ |
Upload File : |
<?php
/**
* Custom Widgets for this theme.
*
* @package synapse
*/
class synapse_Recent_Posts extends WP_Widget {
public function __construct() {
parent::__construct(
'synapse_rp', // Base ID
__('Synapse Recent Posts with Thumbnails', 'synapse'), // Name
array( 'description' => __( 'Display your recent posts, with a Thumbnail.', 'synapse' ), ) // Args
);
}
public function widget( $args, $instance ) {
if (isset($instance['title'])) :
$title = apply_filters( 'widget_title', $instance['title'] );
$no_of_posts = apply_filters( 'no_of_posts', $instance['no_of_posts'] );
else :
$title = __('Latest Posts','synapse');
$no_of_posts = 5;
endif;
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
// WP_Query arguments
$qa = array (
'post_type' => 'post',
'posts_per_page' => $no_of_posts,
'offset' => 0,
'ignore_sticky_posts' => 1
);
// The Query
$recent_articles = new WP_Query( $qa );
if($recent_articles->have_posts()) : ?>
<ul class="rp">
<?php
while($recent_articles->have_posts()) :
$recent_articles->the_post();
?>
<li class='rp-item'>
<?php if( has_post_thumbnail() ) : ?>
<div class='rp-thumb'><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail',array( 'alt' => get_the_title())); ?></a></div>
<?php
else :
?>
<div class='rp-thumb'><a href="<?php the_permalink(); ?>"><img alt="<?php the_title() ?>" src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/nthumb.png"></a></div>
<?php
endif; ?>
<div class='rp-title'><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class='rp-date'><?php the_time(__('M j, Y','synapse')); ?></div>
</li>
<?php
endwhile;
else:
?>
<?php esc_html_e('Oops, there are no posts.','synapse') ?>
<?php
endif;
?>
</ul>
<?php
echo $args['after_widget'];
}
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Latest Articles', 'synapse' );
}
if ( isset( $instance[ 'no_of_posts' ] ) ) {
$no_of_posts = $instance[ 'no_of_posts' ];
}
else {
$no_of_posts = 5;
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:','synapse' ); ?></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 esc_attr( $title ); ?>" />
<label for="<?php echo $this->get_field_id( 'no_of_posts' ); ?>"><?php esc_html_e( 'No. of Posts:', 'synapse' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'no_of_posts' ); ?>" name="<?php echo $this->get_field_name( 'no_of_posts' ); ?>" type="text" value="<?php echo esc_attr( $no_of_posts ); ?>" />
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
$instance['no_of_posts'] = ( ! empty( $new_instance['no_of_posts'] ) ) ? strip_tags( $new_instance['no_of_posts'] ) : '5';
if ( is_numeric($new_instance['no_of_posts']) == false ) {
$instance['no_of_posts'] = $old_instance['no_of_posts'];
}
return $instance;
}
}
add_action( 'widgets_init', 'register_synapse_widget' );
function register_synapse_widget() {
register_widget( 'synapse_Recent_Posts' );
}