Skip to content

Instantly share code, notes, and snippets.

View theodorocaliari's full-sized avatar
💻

Theodoro Caliari theodorocaliari

💻
View GitHub Profile
<?php
/* 1. Back End Usage
---------------------------------------------------------------------*/
// add neccessary actions
// @see http://codex.wordpress.org/Function_Reference/add_action
add_action( 'add_meta_boxes', 'rg_add_custom_box' );
add_action( 'save_post', 'rg_save_postdata', 10, 1 );
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
<div id="colunistas">
<h2>Colunistas</h2>
<ul>
<?php
$teste = array();
// 01
$the_query = new WP_Query('posts_per_page=1');
while ( $the_query->have_posts() ) : $the_query->the_post();
array_push($teste, get_the_author_meta('id')) ?>
<li><?php the_author(); ?> / <?php the_title(); ?></li>
<?php
function mostra(){
//http://stackoverflow.com/a/15505132 - reference
global $post;
$taxonomies = get_object_taxonomies($post->post_type);
foreach ($taxonomies as $taxonomy) {
$terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) ) {
foreach ( $terms as $term ){
@theodorocaliari
theodorocaliari / youtube-muted-video.html
Last active December 23, 2015 00:29
Play YouTube Video Muted
<!doctype html>
<html>
<body>
<div id="ytplayer"></div>
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
@theodorocaliari
theodorocaliari / function_favicon.php
Created August 20, 2013 19:02
Add favicon in wp and thematic child
<?php
// add favicon to site, add 16x16 or 32x32 "favicon.ico" image to child themes main folder
function childtheme_add_favicon() { ?>
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
<?php }
add_action('wp_head', 'childtheme_add_favicon');
?>
@theodorocaliari
theodorocaliari / get_the_slug.php
Created August 16, 2013 12:38
Get page/post slug in wordpress
<?php
/*paste this in functions.php*/
function the_slug() {
global $post;
$slug = $post->post_name;
return $slug;
}
/* --- */
/*call your slug in your page*/
@theodorocaliari
theodorocaliari / limit_char_number.php
Created August 8, 2013 10:54
Limit character number in wordpress. Limitar número de caracteres no wordpress. Reference: http://bavotasan.com/2009/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
<?php
#limit chars
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
@theodorocaliari
theodorocaliari / add_excerpt_in_pages.php
Created August 8, 2013 10:51
Add excerpt in wordpress pages. Adicionar resumo nas paginas do wordpress.
<?php
add_action('init', 'my_custom_init');
function my_custom_init() {
add_post_type_support( 'page', 'excerpt' );
}
?>
<?php
/*remove comments*/
//http://themeshaper.com/forums/topic/removing-comments-section-from-thematic
function remove_comments(){
if (is_page()){
remove_action('thematic_comments_template','thematic_include_comments',5);
}
}
add_action('template_redirect','remove_comments');