Skip to content

Instantly share code, notes, and snippets.

@beovulf
beovulf / post_per_page_cpt.php
Created January 24, 2016 16:02
Set the number of posts for the custom post type
function set_posts_per_page_for_towns_cpt( $query ) {
if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'szkoa' ) ) {
$query->set( 'posts_per_page', '12' );
}
}
add_action( 'pre_get_posts', 'set_posts_per_page_for_towns_cpt' );
// set posts per page for custom post type
@beovulf
beovulf / category_description_single_post.php
Created January 25, 2016 10:10
Get category description from single post
<?php
$category = get_the_category();
echo $category[0]->category_description;
?>
@beovulf
beovulf / ACF_img_object.php
Created February 2, 2016 09:46
Advanced Custom Fields Image Object
<?php $count_posts = 0;
$q = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 4 ) );
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
$count_posts = $count_posts+1;
$obraz_wyrozniajacy = get_field('obraz_wyrozniajacy');
$size_1 = 'thumbnail';
$size_2 = 'medium';
$size_3 = 'large';
$size_4 = 'full';
@beovulf
beovulf / category_name.php
Created February 2, 2016 10:21
Get category name
<?php $category = get_the_category();echo $category[0]->cat_name; ?>
@beovulf
beovulf / mailpoet_newsletter.css
Created February 2, 2016 14:58
Mailpoet newsletter config
.formErrorContent {
display: none;
}
.wysija-input {
width:100%;
font-size:14px;
display:inline-block;
}
.wysija-paragraph {
@beovulf
beovulf / excerpt_length.php
Created February 2, 2016 20:54
Excerpt length limit by word
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
@beovulf
beovulf / Loop_direct_children.php
Created February 3, 2016 07:59
Loop direct children
<?php $q = new WP_Query( array( 'post_type' => 'page', 'post_parent' => 97, 'depth' => 1 ) );
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
?>
<?php endwhile; endif;?>
@beovulf
beovulf / Absolute_centering.css
Created February 3, 2016 09:16
Absolute centering
.absolute-center {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
@beovulf
beovulf / Inline_nowhitespace.css
Last active February 3, 2016 09:16
Inline block without whitespace
parent {
font-size: 0;
}
/* remove atribute from parent */
children {
font-size: 10px;
}
/* reinitialize atribute on children level */
@beovulf
beovulf / wordpress_img.php
Last active February 3, 2016 09:32
Wordpress img
<img src="<?php echo get_template_directory_uri(); ?>/img/our_guests.jpg" alt="" class="img-responsive" />