Different usefull stuff for wordpress
//начало для CSS
/*
Theme Name: Rose
Theme URI: http://zacompom.ru/services
Description: Тема Wordpress
Author: Zagoruyko Victor / info@zacompom.ru
Author URI: http://zacompom.ru
Version: 1.0
*/
------------------------------------------------------------------------------------------------------------------------------
//начало PHP
<?php
/**
*
* @package WordPress
* @subpackage elite
* @since elite 1.0
* Author: Zagoruyko Victor / info@zacompom.ru
*/
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="author" content="Zagoruyko Victor / info@zacompom.ru" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php if ( is_singular() && pings_open( get_queried_object() ) ) : ?>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php endif; ?>
<?php wp_head(); ?>
</head>
<meta name="viewport" content="width=1200", initial-scale=1.0">
---------------------------------------------------------------------------------------------------------------------------------
<?php echo get_template_directory_uri(); ?>/
<?php echo bloginfo('template_url'); ?>/
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
---------------------------------------------------------------------------------------------------------------------------------
page
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php remove_filter( 'the_content', 'wpautop' ); ?>
<?php the_content(); ?>
<?php //comments_template( '', true ); ?>
<?php endwhile; ?>
---------------------------------------------------------------------------------------------------------------------------------
single
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php //comments_template( '', true ); ?>
<?php endwhile; ?>
---------------------------------------------------------------------------------------------------------------------------------
//category
<?php if ( have_posts() ){
while ( have_posts() ){ the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php remove_filter( 'the_content', 'wpautop' );
the_content();
comments_template( '', true );}
} else {
echo wpautop( 'Постов для вывода не найдено.' );
} ?>
----------------------------------------------------------------------------------------------------------------------------------
//Как вывести записи из одной определенной рубрики
<?php if ( have_posts() ) : // если имеются записи в блоге.
query_posts('cat=10&showposts=1&order=ASC'); // указываем ID рубрик, которые необходимо вывести.
while (have_posts()) : the_post(); // запускаем цикл обхода материалов блога
?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php endwhile; endif; wp_reset_query(); ?>
---------------------------------------------------------------------------------------------------------------------------------
всплывашка
<!-- форма -->
<div id="overlay"></div>
<div id="popup">
<span class="close-popup"></span>
<div class="forma">
<?php echo do_shortcode( '[сontaсt-form-7 id="4" title="Контактная форма 1"]' ); ?>
</div></div>
<!-- /форма -->
#overlay
{
position:fixed;
width: 100%;
height: 100%;
background: rgba(102, 102, 102, 0.7);
z-index:100;
display:none;
}
#popup
{
position:fixed;
z-index:105;
width:430px;
left:50%;
top:50%;
margin:-150px 0 0 -260px;
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
/*background:#fff;*/
display:none;
padding:10px 25px 20px 20px;
color: #e20e7d;
border: 1px solid #A70000;
/*background: #c9c1b8;*/
background: #fff url(images/evak.jpg) no-repeat left bottom;
}
.close-popup
{
display:block;
width: 23px;
height:23px;
background:url(images/close.png) no-repeat;
position:absolute;
top:5px;
right:5px;
cursor: pointer;
}
----------------------------------------------------------------------------------------------------------------------------------
//WordPress Contact Form 7: редирект после отправки
on_sent_ok: "location.replace('http://www.YOURSITE.com');"
on_sent_ok: "setTimeout('location.replace("http://test3.trust-finans.ru/thanks");', 3000);"
---------------------------------------------------------------------------------------------------------------------------------
// Clearfix
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
----------------------------------------------------------------------------------------------------------------------------------
//регистрация меню
add_action('init', 'register_nav_menus_on_init');
function register_nav_menus_on_init() {
register_nav_menus(array(
'top-menu' => 'Top Menu',
'sidebar-menu' => 'SideBar Menu',
'footer-menu' => 'Footer Menu',
));
}
// Вывод меню
<?php wp_nav_menu( array( 'theme_location' => 'top-menu' ) ); ?>
----------------------------------------------------------------------------------------------------------------------------------
// активация меню
if (function_exists('add_theme_support')) {
add_theme_support('menus');
}
----------------------------------------------------------------------------------------------------------------------------------
// Регистрация виджетов
function zacompom_widgets_init() {
//require get_template_directory() . '/inc/widgets.php';
register_widget( 'zacompom_maim_widget' );
register_sidebar( array(
'name' => __( 'Header Widget', 'zacompom' ),
'id' => 'sidebar-1',
'description' => __( 'Виджет в шапке сайта.', 'zacompom' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Sidebar Widget', 'zacompom' ),
'id' => 'sidebar-2',
'description' => __( 'Виджет в сайдбаре сайта .', 'zacompom' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer widget', 'zacompom' ),
'id' => 'sidebar-3',
'description' => __( 'Виджет в подвале сайта.', 'zacompom' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'zacompom_widgets_init' );
// Вывод виджета
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
//виджет
<?php if (!dynamic_sidebar("Second Front Page Widget Area") ) : ?>
<!-- Код который будет выводиться если в вашей области не добавлено -->
<!-- ни одного виджета -->
<?php endif; ?>
----------------------------------------------------------------------------------------------------------------------------------
<?php echo do_shortcode( '[сontaсt-form-7 id="4" title="Контактная форма 1"]' ); ?>
----------------------------------------------------------------------------------------------------------------------------------
//Разные single или sidebar
<?php if (is_category(9)) {
// для постов 9 категории
include(TEMPLATEPATH . '/single2.php');
} else {
// для других постов
include(TEMPLATEPATH . '/single1.php');
}
?>
----------------------------------------------------------------------------------------------------------------------------------
//Вывод миниатюр wordpress
<?php if ( has_post_thumbnail()) {the_post_thumbnail(array(170, 170),array("class"=>"alignleft post_thumbnail"));} ?>
----------------------------------------------------------------------------------------------------------------------------------
// Форма поиска
function wpbsearchform( $form ) {
$form = '<form method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div><label class="screen-reader-text" for="s">' . __('') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Найти') .'" />
</div>
</form>';
return $form;
}
add_shortcode('wpbsearch', 'wpbsearchform');
//Вывод формы поиска
<?php echo do_shortcode( '[wpbsearch]' ); ?>
----------------------------------------------------------------------------------------------------------------------------------
Карта Яндекса на сайт
<div class="down_block_left">
<script src="http://api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU" type="text/javascript"></script>
<div id="map" style="width: 365px; height: 305px"></div>
<script type="text/javascript">
ymaps.ready(init);
var myMap;
function init(){
myMap = new ymaps.Map ("map", {
center: [51.638126, 39.27323],
zoom: 17,
});
var myPlacemark = new ymaps.Placemark(
[51.638126, 39.27323]
);
myMap.geoObjects.add(myPlacemark);
}
</script>
</div>
---------------------------------------------------------------------------------------------------------------------------------
<?php if($my_field=get_field("my_field")){echo $my_field;}?>
http://help-wp.ru/acf-advanced-custom-fields-wordpress/
----------------------------------------------------------------------------------------------------------------------------------
вывод постов
if (is_single('1553'))
[nggallery id=1]
----------------------------------------------------------------------------------------------------------------------------------
/* ПЕРВУЮ КАРТИНКУ В КАЧЕСТВЕ МИНИАТЮРЫ */
function get_post_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
//Если на странице нет картинок, то ставим картинку по-умолчанию
if(empty($first_img)){
$img_dir = get_bloginfo('template_directory');
$first_img = $img_dir . '/images/post-default.jpg';
}
return $first_img;
}
Вывод
<img src="<?php echo get_post_image(); ?>" alt="<?php the_title(); ?>" class="alignleft" />
----------------------------------------------------------------------------------------------------------------------------------
// колонка "ID" для таксономий (рубрик, меток и т.д.) в админке
foreach (get_taxonomies() as $taxonomy) {
add_action("manage_edit-${taxonomy}_columns", 'tax_add_col');
add_filter("manage_edit-${taxonomy}_sortable_columns", 'tax_add_col');
add_filter("manage_${taxonomy}_custom_column", 'tax_show_id', 10, 3);
}
add_action('admin_print_styles-edit-tags.php', 'tax_id_style');
function tax_add_col($columns) {return $columns + array ('tax_id' => 'ID');}
function tax_show_id($v, $name, $id) {return 'tax_id' === $name ? $id : $v;}
function tax_id_style() {print '<style>#tax_id{width:4em}</style>';}
// колонка "ID" для постов и страниц в админке
add_filter('manage_posts_columns', 'posts_add_col', 5);
add_action('manage_posts_custom_column', 'posts_show_id', 5, 2);
add_filter('manage_pages_columns', 'posts_add_col', 5);
add_action('manage_pages_custom_column', 'posts_show_id', 5, 2);
add_action('admin_print_styles-edit.php', 'posts_id_style');
function posts_add_col($defaults) {$defaults['wps_post_id'] = __('ID'); return $defaults;}
function posts_show_id($column_name, $id) {if ($column_name === 'wps_post_id') echo $id;}
function posts_id_style() {print '<style>#wps_post_id{width:4em}</style>';}
----------------------------------------------------------------------------------------------------------------------------------
Вывод определенной страницы
<?php
$id = 6938;// Обязательно передавать переменную - это id страницы
$post = get_page($id); // get_page можно поменять на get_post
$main_title = $post->post_title; // title страницы
$content = $post->post_content; // content страницы
echo '<h1>'. $main_title .'</h1>';
echo $content;
?>
----------------------------------------------------------------------------------------------------------------------------------
var top_show = 250; // В каком положении полосы прокрутки начинать показ кнопки "Наверх"
var delay = 2000; // Задержка прокрутки
vikz(document).ready(function() {
vikz(window).scroll(function () { // При прокрутке попадаем в эту функцию
/* В зависимости от положения полосы прокрукти и значения top_show, скрываем или открываем кнопку "Наверх" */
if (vikz(this).scrollTop() > top_show) vikz('#top').fadeIn();
else vikz('#top').fadeOut();
});
vikz('#top').click(function () { // При клике по кнопке "Наверх" попадаем в эту функцию
/* Плавная прокрутка наверх */
vikz('body, html').animate({
scrollTop: 0
}, delay);
});
});
-------------------------
<a onclick="yaCounter41536404.reachGoal('ALLPHOTO'); return true;" href="/galereya">