Skip to content

Instantly share code, notes, and snippets.

View pedrorvidal's full-sized avatar

Pedro Vidal pedrorvidal

  • Porto Alegre, Brazil.
View GitHub Profile
#!/bin/bash
# requires lynx,grep,awk,uniq,sort,egrep,head,xargs,wget,tar adn rm
lynx -dump http://br.wordpress.org/releases | /bin/grep "\.tar\.gz$" | awk -F'http://' '{ print "http://"$2 }' | uniq | sort -r | /bin/egrep -v 'RC|beta' | head -n1 | xargs wget -O wordpress-br.tar.gz
tar -xvf wordpress-br.tar.gz
/bin/rm wordpress-br.tar.gz
$(document).ready(function(){
// this is the container we'll load content into
var container = $('#target');
// adding a tabIndex of -1 makes it keyboard accessible,
// and we can set the focus to it
container.attr('tabIndex','-1');
// if a user clicks on an element with the class ajaxtrigger...
@pedrorvidal
pedrorvidal / estados-br.html
Last active August 29, 2015 13:56
Combo de estados do Brasil
<select name="Combo_Estados">
<option value="AC">AC</option>
<option value="AL">AL</option>
<option value="AM">AM</option>
<option value="AP">AP</option>
<option value="BA">BA</option>
<option value="CE">CE</option>
<option value="DF">DF</option>
<option value="ES">ES</option>
<option value="GO">GO</option>
@pedrorvidal
pedrorvidal / unserialize
Created February 20, 2014 20:44
Unserialize jquery serialized forms
//JS (Jquery)
var serializedData = $('#myForm').serialize();
$.post(
'getSerializedData.php',
{data:serializedData},
function(data){
}
)
// PHP
$serializedData = $_POST['data'];
@pedrorvidal
pedrorvidal / listar-taxonomias.php
Last active August 29, 2015 13:56
Pegar uma custom taxonomy e mostrar ela ordenada com filhos agrupados.
<?php
$taxonomyName = "slug-da-minha-taxonomia";
$terms = get_terms($taxonomyName,array('parent' => 0));
foreach($terms as $term) :
echo '<a href="'.get_term_link($term->slug,$taxonomyName).'">'.$term->name.'</a>';
$term_children = get_term_children($term->term_id,$taxonomyName);
echo '<ul>';
foreach($term_children as $term_child_id) :
$term_child = get_term_by('id',$term_child_id,$taxonomyName);
echo '<li><a href="' . get_term_link( $term_child->name, $taxonomyName ) . '">' . $term_child->name . '</a></li>';
add_theme_support(
'infinite-scroll',
array(
'type' => 'scroll',
'footer_widgets' => false,
'container' => 'products',
'wrapper' => false,
'render' => false,
'posts_per_page' => get_option( 'posts_per_page' )
)
<?php
$args = array(
'post_type' => 'oferta',
'posts_per_page' => 12,
'order' => 'DESC'
);
$q = new WP_Query($args);
global $post;
while ($q->have_posts()) : $q->the_post(); ?>
<li>
<div class="img">
<?php $imgsrc = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img src="<?php echo $imgsrc; ?>">
</div>
<div class="description">
<header><?php the_title(); ?></header>
<div><?php the_content(); ?></div>
<?php $metas = get_post_meta( $post->ID ); ?>
<div>Est.: <?php echo $metas['estoque'][0]; ?> unidades</div>
@pedrorvidal
pedrorvidal / get-images-except-thumbnail.php
Last active August 29, 2015 13:57
Get all images attached to post
/*
* Get all images EXCEPT post thumbnail
*/
<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
@pedrorvidal
pedrorvidal / search.sh
Last active August 29, 2015 13:58
Search string thru files inside folders recursively
find /var/www -type f -print0 | xargs -0 grep -li 'search string'