Skip to content

Instantly share code, notes, and snippets.

View certainlyakey's full-sized avatar

Aleksandr Beliaev certainlyakey

  • Nortal AS
  • Tallinn
View GitHub Profile
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - register widget areas
function widgets_init_now() {
register_sidebar( array(
'name' => 'В шапке',
'id' => 'header'
) );
register_sidebar( array(
'name' => 'Левая колонка',
'id' => 'aside_left'
) );
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - hide admin bar
add_filter('show_admin_bar', '__return_false');
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - custom content function with manual word limit
//Custom content function with words manual limit
function content($limit, $postid, $showmorelink = true) { //Normally, the second parameter provided is '$post->ID'
$content = explode(' ', get_post_field('post_content', $postid), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content);
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'<br />');
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - add excerpts to pages
//add excerpts to pages
add_action( 'init', 'add_excerpts_to_pages' );
function add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - the_category expanded to support custom taxonomies, with possibility to exclude certain categories or terms
//the_category expanded to support custom taxonomies, with possibility to exclude certain categories/terms
function catOut($category,$tax,$showlink) {
$text = '';
$text .= '<li>';
if ($showlink) {$text .= '<a href="' . get_term_link($category->term_id,$tax).'" title="'.$category->name.'"'.'>';}
$text .= $category->name;
if ($showlink) {$text .= '</a>';}
$text .= '</li>';
return $text;
}
@certainlyakey
certainlyakey / page.php
Last active August 29, 2015 13:56
Wordpress - custom gallery from WP post gallery
<?php
$args = array(
'numberposts' => -1, // Using -1 loads all posts
'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
'order'=> 'ASC',
'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
'post_status' => null,
'post_type' => 'attachment'
);
@certainlyakey
certainlyakey / functions.php
Created March 3, 2014 21:34
Wordpress - register custom post type
//Add custom post type (books)
function book_custompost_init() {
$labels_books = array(
'name' => _x('Публикации', 'post type general name'),
'singular_name' => _x('Публикация', 'post type singular name'),
'add_new' => _x('Добавить', 'book'),
'add_new_item' => __('Добавить '),
'edit_item' => __('Редактировать публикацию'),
'new_item' => __('Новая публикация'),
'all_items' => __('Все публикации'),
@certainlyakey
certainlyakey / functions.php
Created March 3, 2014 21:34
Wordpress - register custom taxonomy for custom post type
//Create categories for books
function create_booktag_taxonomy() {
$labels_booktag = array(
'name' => _x( 'Тэги публикаций', 'taxonomy general name' ),
'singular_name' => _x( 'Тэг публикаций', 'taxonomy singular name' ),
'search_items' => __( 'Искать тэги публикаций' ),
'all_items' => __( 'Все тэги публикаций' ),
'edit_item' => __( 'Редактировать' ),
'update_item' => __( 'Обновить' ),
'add_new_item' => __( 'Добавить тэг публикаций' ),
@certainlyakey
certainlyakey / functions.php
Last active August 29, 2015 13:56
Wordpress - register tag taxonomy for pages
//Create categories for pages
function create_pages_taxonomy() {
$labels_pages_cat = array(
'name' => _x( 'Теги страниц', 'taxonomy general name' ),
'singular_name' => _x( 'Тег страницы', 'taxonomy singular name' ),
'search_items' => __( 'Искать теги страниц' ),
'all_items' => __( 'Все теги страниц' ),
// 'parent_item' => __( 'Родительская категория страниц' ),
// 'parent_item_colon' => __( 'Родительская категория страниц' ),
'edit_item' => __( 'Редактировать' ),
@certainlyakey
certainlyakey / header.php
Created March 10, 2014 08:46
Wopdpress - nav menu
<?php wp_nav_menu( array( 'theme_location' => 'secmenu', 'container_class' => 'secmenu', 'container' => 'nav' ) ); ?>