Skip to content

Instantly share code, notes, and snippets.

View levnhub's full-sized avatar
🎯
Focusing

Lev N levnhub

🎯
Focusing
View GitHub Profile
@levnhub
levnhub / wp-loops.php
Last active July 27, 2018 01:27
wp loops
<?php // Выводим посты
global $post; // не обязательно
// параметры по умолчанию
$args = array(
'numberposts' => 5, // 5 записей
'category' => 9, // из рубрики 9
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
@levnhub
levnhub / wp-acf-repeater.php
Last active August 15, 2017 10:15
Wordpress ACF Repeater
<?php if( have_rows('repeater_field_name') ): ?>
<?php while( have_rows('repeater_field_name') ): the_row();
$image = get_sub_field('image');
$content = get_sub_field('content');
?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php echo $content; ?>
@levnhub
levnhub / php-server-tweaks
Last active October 28, 2017 02:40
PHP Server Tweaks
// .htaccess
php_value max_input_vars 3000
php_value max_execution_time 120
// Indexes
DirectoryIndex myindex.php
Options +Indexes
// Password
AuthType Basic
@levnhub
levnhub / wp-functions.php
Last active July 31, 2018 15:12
WP Functions & Hooks
<?php
/**
* The main functions file
*
*/
// Убираем лишнее
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wlwmanifest_link' );
@levnhub
levnhub / wp-post-template
Created October 6, 2017 17:05
WP Post Template
<?php
/*
* Template Name: НазваниеШаблона
* Template Post Type: post, page, product
*/
get_header();
?>
@levnhub
levnhub / head.php
Last active August 2, 2018 12:43
Useful head
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- for 500px min-width body -->
<!-- <meta name="viewport" content="width=device-width, initial-scale=0.64, maximum-scale=0.64, shrink-to-fit=no"> -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- <meta name="format-detection" content="telephone=no"> -->
<meta name="description" content="<?php bloginfo( 'description' ); ?>">
@levnhub
levnhub / wp-menu.php
Last active August 1, 2018 15:45
WP Menu
<?php
// Работа с меню через wp_get_nav_menu_items();
if ( $menu_items = wp_get_nav_menu_items('Главное меню') ) : ?>
<nav class="main_nav">
<ul class="main_nav--list">
<?php foreach ( (array) $menu_items as $key => $menu_item ) :
@levnhub
levnhub / wp-category.php
Last active June 5, 2018 13:25
WP Category
<?php
// Заменяем шаблон post зависимости от категории (functions.php)
add_filter('template_include', 'service_template');
function service_template( $template ) {
global $post;
if( ( is_single() && in_category( 1, $post ) ) ) {
$template = get_stylesheet_directory() . '/single-service.php';
@levnhub
levnhub / wp-post.php
Created October 13, 2017 00:28
WP Post
// Если на странице поста, выводит "active"
<?php if( is_single( $post ) ) { echo 'active'; }; ?>
@levnhub
levnhub / preload.html
Last active June 5, 2018 13:24
Preload
<style>
.loader {
background: none repeat scroll 0 0 #ffffff;
bottom: 0;
height: 100%;
left: 0;
position: fixed;
right: 0;
top: 0;
width: 100%;