File: /var/www/iq22073873/data/www/bckln.ru/wp-content/themes/dt-the7/functions.php
<?php
/**
* Vogue theme.
*
* @since 1.0.0
*/
// File Security Check
if (!defined('ABSPATH')) {
exit;
}
/**
* Set the content width based on the theme's design and stylesheet.
*
* @since 1.0.0
*/
if (!isset($content_width)) {
$content_width = 1200; /* pixels */
}
/**
* Initialize theme.
*
* @since 1.0.0
*/
require(trailingslashit(get_template_directory()) . 'inc/init.php');
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Technical Security Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Decor Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Artists Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Selection Sites Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Logistics Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Ideas1 Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Ideas2 Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Ideas3 Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Ideas4 Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Ideas5 Sidebar',
'before_widget' => '<div class="widget-category">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => 'Completed Projects Sidebar',
'before_widget' => '<div class="widget-gallery">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
if (function_exists('add_image_size')) {
add_image_size('portfolio-thumb', 450, 450, array('center', 'center')); // Кадрирование изображения
}
function wp_get_cat_postnum($id)
{
$cat = get_category($id);
$count = (int) $cat->count;
$taxonomy = 'category';
$args = array('child_of' => $id, );
$tax_terms = get_terms($taxonomy, $args);
foreach ($tax_terms as $tax_term) {
$count += $tax_term->count;
}
return $count;
}
class trueTopPostsWidget extends WP_Widget
{
/*
* создание виджета
*/
function __construct()
{
parent::__construct(
'true_top_widget',
'Посты услуг', // заголовок виджета
array('description' => 'Позволяет вывести посты, отсортированные по количеству комментариев в них.') // описание
);
}
/*
* фронтэнд виджета
*/
public function widget($args, $instance)
{
$title = apply_filters('widget_title', $instance['title']); // к заголовку применяем фильтр (необязательно)
$cat = $instance['cat'];
echo $args['before_widget'];
if (!empty($title))
echo $args['before_title'] . $title . $args['after_title'];
$my_posts = new WP_Query;
$myposts = $my_posts->query(array(
'page_id' => 14813,
));
?>
<ul class="gallery portfolio clearfix">
<?php
foreach ($myposts as $pst) {
$a = $pst->ID;
if ($pd = get_field('gallery-photo', $a)) {
shuffle($pd);
// ограничим вывод 4 элементами
// $pd = array_slice($pd, 0, 4);
foreach ($pd as $el) {
echo '<li>';
echo '<a data-fancybox="portfolio-gallery" href="' . wp_get_attachment_image_url($el['image'], 'full') . '" data-caption="' . $el['text'] . '">';
echo wp_get_attachment_image($el['image'], array(647, 400));
echo '<span class="hold-img">' . $el['text'] . '</span>';
echo '</a>';
echo '</li>';
}
}
}
?>
</ul>
<?php
//echo '<a class="count-item" href="#" ><span class="text-bold"></span> проектов</a>';
wp_reset_postdata();
echo $args['after_widget'];
}
/*
* бэкэнд виджета
*/
public function form($instance)
{
if (isset($instance['title'])) {
$title = $instance['title'];
}
if (isset($instance['cat'])) {
$cat = $instance['cat'];
}
?>
<!--<p>
<label for="<?php echo $this->get_field_id('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>-->
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">Введите slug рубрики :</label>
<input id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>"
type="text" value="<?php echo ($cat) ? esc_attr($cat) : '1'; ?>" />
</p>
<?php
}
/*
* сохранение настроек виджета
*/
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
$instance['cat'] = (is_string($new_instance['cat'])) ? $new_instance['cat'] : '';
return $instance;
}
}
/*
* регистрация виджета
*/
function true_top_posts_widget_load()
{
register_widget('trueTopPostsWidget');
}
add_action('widgets_init', 'true_top_posts_widget_load');
class completed_Projects extends WP_Widget
{
/*
* создание виджета
*/
function __construct()
{
parent::__construct(
'completed_Projects',
'Реализованные проекты', // заголовок виджета
array('description' => 'Позволяет вывести посты, отсортированные по количеству комментариев в них.') // описание
);
}
/*
* фронтэнд виджета
*/
public function widget($args, $instance)
{
$title = apply_filters('widget_title', $instance['title']); // к заголовку применяем фильтр (необязательно)
$cat = $instance['cat'];
echo $args['before_widget'];
if (!empty($title))
echo $args['before_title'] . $title . $args['after_title'];
$my_posts = new WP_Query;
$myposts = $my_posts->query(array(
'post_type' => 'page',
'post_parent' => 14816,
'numberposts' => 4,
'orderby' => 'date',
'order' => 'ASC'
));
?>
<div class="gallery-item">
<a href="#" class="link-prev">prev</a>
<a href="#" class="link-next">next</a>
<div class="gallery-holder">
<ul>
<?php
foreach ($myposts as $pst) {
$a = $pst->ID;
if ($pd = get_field('gallery-photo', $a)) {
;
foreach ($pd as $el) {
echo '<li>';
echo '<a data-fancybox="portfolio_gallery" href="' . wp_get_attachment_image_url($el['image'], 'full') . '" data-caption="' . $el['text'] . '">';
echo '<span class="hold-img" style="background: url(' . wp_get_attachment_image_url($el['image'], 'full') . '); background-position:50% 0;background-size: cover;"></span>';
echo '<strong class="title">' . $el['text'] . '</strong>';
echo '</a>';
echo '</li>';
}
}
}
?>
</ul>
</div>
</div>
<?php
wp_reset_postdata();
?>
<?php
echo $args['after_widget'];
}
/*
* бэкэнд виджета
*/
public function form($instance)
{
if (isset($instance['title'])) {
$title = $instance['title'];
}
if (isset($instance['cat'])) {
$cat = $instance['cat'];
}
?>
<p>
<label for="<?php echo $this->get_field_id('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>
<!--<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">Введите slug рубрики :</label>
<input id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>" type="text" value="<?php echo ($cat) ? esc_attr($cat) : '1'; ?>" />
</p>-->
<?php
}
/*
* сохранение настроек виджета
*/
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
$instance['cat'] = (is_string($new_instance['cat'])) ? $new_instance['cat'] : '';
return $instance;
}
}
/*
* регистрация виджета
*/
function true_completed_projects()
{
register_widget('completed_Projects');
}
add_action('widgets_init', 'true_completed_projects');