Skip to content

Instantly share code, notes, and snippets.

View quagliato's full-sized avatar

Eduardo Quagliato quagliato

View GitHub Profile
@quagliato
quagliato / iterate_children_pages.php
Created August 5, 2013 14:14
Iterate children pages
$query = new WP_Query();
$all_pages = $query->query(
array(
'post_type' => 'page',
'orderby' => 'post_title',
'order' => 'ASC',
'posts_per_page' => -1));
$children = get_page_children(get_the_ID(), $all_pages);
@quagliato
quagliato / create_post-type.php
Created August 5, 2013 14:21
Create a new post-type
// Dentro do functions.php no diretório do tema, adicione o seguinte código:
/*
* Post Type: NOME
*/
add_action('init', 'post_type_register');
function post_type_register() {
$labels = array(
@quagliato
quagliato / align_div_vertically.js
Created August 6, 2013 20:17
Align a div vertically on the screen
var div_to_be_aligned = $('#middle');
var new_margin_top = 0;
var descontos = 0;
new_margin_top = (document.height - descontos - div_to_be_aligned.height()) / 2;
new_margin_top = new_margin_top + descontos / 2;
div_to_be_aligned.css('margin-top', new_margin_top + 'px');
@quagliato
quagliato / iterate_post-type.php
Created September 6, 2013 20:42
Iterate a specific post-type
<?php
$query = new WP_Query(
array(
'post_type' => '<post-type-name>'
)
);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
@quagliato
quagliato / iterate_all_images_of_a_post.php
Last active December 22, 2015 12:08
Iterate all images of a post
<?php
$images = get_posts(
array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'exclude' => get_post_thumbnail_id() // to exclude the featured image
)
);
foreach($images as $image){
@quagliato
quagliato / iterate_pages_and_create_sections.php
Created September 27, 2013 04:44
Iterate WP pages and create <section> for them
<?php
$pages = get_pages(
array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'post_type' => 'page',
'posts_per_page' => 999
)
);
@quagliato
quagliato / 301redirect_no-www_to_www.txt
Created October 22, 2013 13:26
Redirect 301 from no-www URL to www URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^copacabanaclub\.com\.br$
RewriteRule ^(.*) http://www.copacabanaclub.com.br/$1 [R=301]
@quagliato
quagliato / print_custom-field_value.php
Created October 24, 2013 17:54
Print custom-field values
echo get_post_meta(get_the_ID(), 'key', true);
@quagliato
quagliato / print_categories_of_a_post_with_links.php
Created October 24, 2013 18:15
Print categories of a post, with links
<?php
$cats = get_the_category(get_the_id());
$separator = ', ';
$output = '';
foreach($cats as $cat){
$output =
'<a href="'.
get_category_link($cat->term_id).
'" title="'.
esc_attr(sprintf(__("Veja todos os posts em %s"), $cat->name)).
@quagliato
quagliato / iterate_categories_and_print_its_links.php
Created October 29, 2013 15:56
Iterate all categories and prints its links.