$args = [
'post_type' => ['post','service'],
'post__in' => [5,12,2,14,7],
'orderby' => 'post__in',
];
$loop = new WP_Query( $args );
if ( get_post_type() === 'service' ) {
get_template_part( 'templates/archive/archive-service' );
} else {
get_template_part( 'templates/archive/archive-common' );
}
$post_type = get_post_type();
if ( file_exists( get_theme_file_path( 'templates/archive/archive-' . $post_type . '.php' ) ) ) {
get_template_part( 'templates/archive/archive-' . $post_type );
} else {
get_template_part( 'templates/archive/archive-common' );
}
// Shortcode for projects [projects-list posts="3"]
function projects_listing_parameters_shortcode( $atts ) {
ob_start();
$args = shortcode_atts( array (
'type' => 'projects',
'posts' => 6,
'cat' => ''
), $atts );
$options = array(
'post_type' => $args['type'],
'posts_per_page' => $args['posts'],
'tax_query' => array(
array (
'taxonomy' => 'project',
'field' => 'slug',
'terms' => $args['cat'],
)
),
);
$query = new WP_Query( $options );
if ( $query->have_posts() ) $item = 0; {
while ( $query->have_posts() ) : $query->the_post(); $item++;
echo '<div class="item item-' . $item . '">';
get_template_part( 'template-parts/project-cards', get_post_format() );
echo '</div>';
endwhile;
wp_reset_postdata();
$myvariable = ob_get_clean();
return $myvariable;
}
}
add_shortcode( 'projects-list', 'projects_listing_parameters_shortcode' );
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
function custom_scripts() {
// Сюда стили
wp_enqueue_style( 'newstyle', get_template_directory_uri() . '/assets/css/custom_style.min.css' );
// Сюда скрипты
wp_enqueue_script( 'newscript', get_template_directory_uri() . '/assets/js/custom_script.min.js' );
// сюда инициализацию или отдельным файлом как выше
$newscript_init = 'jQuery(function($) {
});';
wp_add_inline_script( 'newscript', $newscript_init );
}
add_action( 'wp_footer', 'the_popup_form', 1 );
function the_popup_form() { ?>
<div id="popup" class="mfp-hide popup">
<form id="popup-form" class="popup-form">
<!-- ... -->
</form>
</div>
<?php }
pre_get_users
add_action( 'pre_get_users', 'custom_pre_get_users', 1 );
function custom_pre_get_users( $query ) {
if ( is_admin() && $query->is_main_query() )
$query->set( 'orderby', 'nicename' );
}
post_gallery
.<?php
function my_post_gallery( $output, $attr, $instance ) {
$_attachments = get_posts( array('include' => $attr['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => $attr['orderby']) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
if ( empty( $attachments ) ) {
return '';
}
ob_start();
?>
<div class="gallery">
<?php
foreach ( $attachments as $i => $image ) :
$url = wp_get_attachment_url( $image->ID );
?>
<a href="<?php echo $url; ?>" class="gallery-item">
<?php echo wp_get_attachment_image( $image->ID, 'thumbnail' ); ?>
</a>
<?php endforeach; ?>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_filter( 'post_gallery', 'my_post_gallery', 10, 3 );
// Подпишемся на ресайз и продиспатчим его для запуска
$(window).on('resize', function(e){
// Переменная, по которой узнаем запущен слайдер или нет.
// Храним её в data
var init = $(".card-box").data('init-slider');
// Если мобильный
if(window.innerWidth < 480){
// Если слайдер не запущен
if(init != 1){
// Запускаем слайдер и записываем в data init-slider = 1
$('#card-box').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1
}).data({'init-slider': 1});
}
}
// Если десктоп
else {
// Если слайдер запущен
if(init == 1){
// Разрушаем слайдер и записываем в data init-slider = 0
$('#card-box').slick('unslick').data({'init-slider': 0});
}
}
}).trigger('resize');
<?php
function img_resize($src, $dest, $width, $height, $rgb = 0xFFFFFF, $quality = 100) {
if (!file_exists($src)) {
return false;
}
$size = getimagesize($src);
if ($size === false) {
return false;
}
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
$icfunc = 'imagecreatefrom'.$format;
if (!function_exists($icfunc)) {
return false;
}
if($width==0)if($size[0]<=800)$width=$size[0];else $width=800;
if($size[0]<$width)$width=$size[0];
if($size[1]<$height)$height=$size[1];
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
if ($height == 0) {
$y_ratio = $x_ratio;
$height = $y_ratio * $size[1];
} elseif ($width == 0) {
$x_ratio = $y_ratio;
$width = $x_ratio * $size[0];
}
$ratio = min($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
$isrc = $icfunc($src);
$idest = imagecreatetruecolor($width, $height);
imagefill($idest, 0, 0, $rgb);
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
header("Content-type: image/jpeg");
imagejpeg($idest);
imagedestroy($isrc);
imagedestroy($idest);
}
header("Content-type: image/jpeg");
header("Cache-control: public");
header("Expires: " . gmdate("D, d M Y H:i:s", date("U")+(86400*365.25)) . " GMT");
img_resize($_GET['pathimage'], $dest, $_GET['width'], $_GET['height'], $rgb = 0xFFFFFF, $quality = 70);
document.addEventListener( 'wpcf7submit', function( event ) {
if ( '123' == event.detail.contactFormId ) {
alert( "The contact form ID is 123." );
// do something productive
}
}, false );