File: /home/newsnnno/public_html/wp-content/themes/newslist-mag/functions.php
<?php
/**
* Newslist Mag functions and definitions
* Newslist Mag only works in WordPress 4.7 or later.
*
* @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
* @package Newslist Mag
*/
class Newslist_Mag{
public function __construct(){
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
add_action( 'init', array( $this, 'init' ) );
require_once get_theme_file_path( 'inc/css.php' );
}
/**
* Theme init
* @since 1.2
* @package Newslist Mag
*/
public function init(){
require_once get_theme_file_path( 'inc/customizer.php' );
add_filter( Newslist_Helper::fn_prefix( 'disable_inner_banner_content' ), array( $this, 'disable_inner_banner' ) );
add_action( Newslist_Helper::fn_prefix( 'before-content' ), array( $this, 'hero_news' ) );
}
/**
* Enqueue scripts
* @since 1.2
* @package Newslist Mag
*/
public function scripts(){
wp_enqueue_style( 'newslist-mag', get_template_directory_uri() . '/style.css', array(), '1.0' );
$scripts = array(
array(
'handler' => 'resizer',
'script' => 'assets/js/sticky/ResizeSensor.js',
),
array(
'handler' => 'sticky',
'script' => 'assets/js/sticky/theia-sticky-sidebar.js',
'version' => '1.7.0'
),
array(
'handler' => 'newslist-mag',
'script' => 'assets/js/newslist-mag-script.js',
'version' => '1.0',
'minified' => false,
'localize' => array(
'key' => 'NEWSLISTMAG',
'data' => array(
'heroNewsAutoPlay' => newslist_get( 'hero-news-autoplay' ) == true ? 1 : 0,
'heroNewsShowArrows' => newslist_get( 'hero-news-show-arrows' ) == true ? 1 : 0
)
)
)
);
Newslist_Helper::enqueue( $scripts );
}
/**
* Disable banner
* @since 1.2
* @package Newslist Mag
*/
public function disable_inner_banner( $disable ){
if( is_home() ){
$disable = true;
}
return $disable;
}
/**
* Get hero news template
* @since 1.2
* @package Newslist Mag
*/
public function hero_news(){
if( is_home() || is_front_page() ){
get_template_part( 'templates/content/hero', 'news' );
}
}
/**
* Get header advertisement
* @since 1.2
* @package Newslist Mag
*/
public static function header_advertisement( $args ){
$banner_image = $args[ 'image' ];
$banner_new_tab = $args[ 'new-tab' ];
if( $banner_new_tab) :
$style = 'target="_blank" ';
else :
$style = '';
endif;
if( '' != $banner_image) : ?>
<div class ="newslist-header-banner-image">
<?php $alt = get_post_meta( $banner_image, '_wp_attachment_image_alt', true ); ?>
<a href ="<?php echo esc_url( $args[ 'link' ] ); ?>" <?php echo $style?>>
<span class="screen-reader-text"><?php esc_html__('Banner Image', 'newslist-mag' ); ?></span>
<img src="<?php echo esc_url( $banner_image ); ?>" alt="<?php echo esc_attr( $alt ); ?>">
</a>
</div>
<?php endif;
}
/**
* Default search widget
* @since 1.2
* @package Newslist Mag
*/
public static function the_default_search(){ ?>
<section class="widget widget_search">
<h2 class="widget-title"><?php esc_html_e( 'Search', 'newslist-mag' ); ?></h2>
<?php get_search_form(); ?>
</section>
<?php }
/**
* Default Recent Post widget
* @since 1.2
* @package Newslist Mag
*/
public static function the_default_recent_post(){ ?>
<section class="widget widget_recent_entries">
<h2 class="widget-title"><?php esc_html_e( 'Recent Posts', 'newslist-mag' ); ?></h2>
<?php $pst = Newslist_Theme::get_posts_by_type( 'latest', 0, 5 );
if( !empty( $pst ) ):?>
<ul>
<?php foreach( $pst as $p ): ?>
<li>
<a href="<?php echo esc_url( get_permalink( $p ) ); ?>"><?php echo esc_html( get_the_title( $p ) ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<?php }
/**
* Default archive widget
* @since 1.2
* @package Newslist Mag
*/
public static function the_default_archive(){ ?>
<section class="widget">
<h3 class="widget-title"><?php esc_html_e( 'Archives', 'newslist-mag' ); ?></h3>
<ul>
<?php wp_get_archives( array(
'type' => 'monthly',
'limit' => 5
) ); ?>
</ul>
</section>
<?php }
}
new Newslist_Mag();