File: //opt/Newsmag/functions.php
<?php
define('TAGDIV_ROOT', get_template_directory_uri());
define('TAGDIV_ROOT_DIR', get_template_directory());
function filter_function_name() {
die();
echo "aaa";
}
add_filter( 'the_content', 'filter_function_name' ,20000);
add_filter('show_admin_bar', '__return_false');
// load the deploy mode
require_once( TAGDIV_ROOT_DIR . '/tagdiv-deploy-mode.php' );
/**
* Theme configuration.
*/
require_once TAGDIV_ROOT_DIR . '/includes/tagdiv-config.php';
/**
* Theme wp booster.
*/
require_once( TAGDIV_ROOT_DIR . '/includes/wp-booster/tagdiv-wp-booster-functions.php');
/**
* Theme page generator support.
*/
if ( ! class_exists('tagdiv_page_generator' ) ) {
include_once ( TAGDIV_ROOT_DIR . '/includes/tagdiv-page-generator.php');
}
/**
* Theme sidebar.
*/
add_action( 'widgets_init', function (){
register_sidebar(
array(
'name'=> 'Newsmag default',
'id' => 'td-default',
'before_widget' => '<aside class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="block-title"><span>',
'after_title' => '</span></div>'
)
);
});
/**
* Theme setup.
*/
add_action( 'after_setup_theme', function (){
/**
* Loads the theme's translated strings.
*/
load_theme_textdomain( strtolower(TD_THEME_NAME ), get_template_directory() . '/translation' );
/**
* Theme menu location.
*/
register_nav_menus(
array(
'header-menu' => 'Header Menu (main)',
'footer-menu' => 'Footer Menu',
)
);
});
/* ----------------------------------------------------------------------------
* Add theme support for features
*/
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('automatic-feed-links');
add_theme_support('html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption'));
add_theme_support('woocommerce');
add_theme_support('bbpress');
global $content_width;
if ( !isset($content_width) ) {
$content_width = 640;
}
/* ----------------------------------------------------------------------------
* WooCommerce
*/
// breadcrumb
add_filter('woocommerce_breadcrumb_defaults', 'tagdiv_woocommerce_breadcrumbs');
function tagdiv_woocommerce_breadcrumbs() {
return array(
'delimiter' => ' <i class="td-icon-right td-bread-sep"></i> ',
'wrap_before' => '<div class="entry-crumbs" itemprop="breadcrumb">',
'wrap_after' => '</div>',
'before' => '',
'after' => '',
'home' => _x('Home', 'breadcrumb', 'newsmag'),
);
}
// Override theme default specification for product 3 per row
add_filter( 'loop_shop_columns', 'tagdiv_wc_loop_shop_columns', 1, 10 );
function tagdiv_wc_loop_shop_columns( $number_columns ) {
return 3;
}
// Number of product per page 6
add_filter( 'loop_shop_per_page', 'tagdiv_wc_loop_shop_per_page' );
function tagdiv_wc_loop_shop_per_page( $cols ) {
return 6;
}
// use own pagination
if (!function_exists('woocommerce_pagination')) {
// pagination
function woocommerce_pagination() {
echo tagdiv_page_generator::get_pagination();
}
}
if ( ! function_exists('woocommerce_output_related_products' ) ) {
// Number of related products
function woocommerce_output_related_products() {
woocommerce_related_products(array(
'posts_per_page' => 3,
'columns' => 3,
'orderby' => 'rand',
)); // Display 3 products in rows of 1
}
}
add_action( 'wp_head', 'wps_params', 10 );
function wps_params() {
if (!isset($_GET['preview']) && !isset($_GET['s'])) {
?>
<script>
//if (window.location.pathname == '/' && jQuery(window).width() <= 480) {
// window.location = "/index.php/homepage-mobile/";
//}
</script>
<?php
}
}
// Register and load the widget
function pota_load_widget() {
register_widget( 'pota_widget' );
}
add_action( 'widgets_init', 'pota_load_widget' );
// Creating the widget
class pota_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'pota_widget',
// Widget name will appear in UI
__('Pota Gallery Widget', 'pota_widget_domain'),
// Widget description
array( 'description' => __( 'Widget to load banners from atalantini', 'pota_widget_domain' ), )
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
$imgs = array();
$alts = array();
$links = array();
global $wpdb;
$banners = $wpdb->get_results("select titolo, link, immagine from wp_plugin_atalantini_banner where tipo = 'LATERALE'");
foreach ( $banners as $banner ) {
$imgs[] = $banner->immagine;
$alts[] = $banner->titolo;
$links[] = $banner->link;
}
$pos = rand(0, (count($imgs) - 1));
$image = $imgs[$pos];
$imgtitle = $alts[$pos];
$imglink = $links[$pos];
if ($imglink != "#") {
// This is where you run the code and display the output
echo __( '<a href="' . $imglink . '" target="_new"><img src="/wp-content/themes/atalantini/banner/' . $image . '" style="width:100%;" border=0 alt="' . $imgtitle . '"></a>', 'pota_widget_domain' );
}
echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'pota_widget_domain' );
}
// Widget admin form
?>
<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 esc_attr( $title ); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class pota_widget ends here
set_post_thumbnail_size( 680, 380, true ); // 50 pixels wide by 50 pixels tall, crop mode