Skip to content

Instantly share code, notes, and snippets.

View leocristofani's full-sized avatar

Leonardo Cristofani leocristofani

View GitHub Profile
@leocristofani
leocristofani / WP functions.php
Last active December 15, 2015 21:39
WordPress Theme's functions.php file with useful constants and boilerplate code for registering menus and sidebars.
<?php
/* DEFINE CONSTANTS
========================================== */
define('THEME_DIR', get_stylesheet_directory_uri() );
define('THEME_IMAGES_DIR', THEME_DIR . '/assets/img' );
/* REGISTER MENUS
========================================== */
@leocristofani
leocristofani / WP style.css
Last active December 15, 2015 21:48
WordPress Theme's style.css boilerplate with description and useful @import to start up.
/*
Theme Name:
Theme URI:
Description:
Version: 1.0
Author:
Author URI:
License:
License URI:
*/
@leocristofani
leocristofani / WP header.php
Last active December 15, 2015 21:49
WordPress Theme's header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><?php wp_title('|', true, 'right'); ?><?php bloginfo('name'); ?></title>
<meta name="description" content="<?php bloginfo('description'); ?>">
<meta name="author" content="">
@leocristofani
leocristofani / WP footer.php
Last active December 15, 2015 21:49
Wordpress Theme's footer.php file.
@leocristofani
leocristofani / WP the loop.php
Last active December 15, 2015 21:50
The famous WordPress Loop, inspired by http://undercores.me starter template.
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); // start the loop ?>
<?php get_template_part('partials/content', get_post_format()); ?>
<?php endwhile; // end the loop ?>
<?php else : ?>
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('main-sidebar')) : ?>
<!-- insert default widgets -->
<div class="sidebar-widget">
<h4><?php _e('Search','theme-name'); ?></h4>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
<!-- get_search_form() -->
<form method="get" action="<?php home_url(); ?>">
<input type="text" name="s" id="s" placeholder="search">
<input type="submit" value="search">
</form>
@leocristofani
leocristofani / WP - post_nav.php
Created April 9, 2013 22:18
Alguns posts em WordPress possuem mais do que uma página, e precisamos criar oferecer links de navegação entre as páginas do post.
<?php
$post_nav_args = array(
'before' => '<p class="post_navigation"',
'after' => '</p>',
'pagelink' => 'Página %'
);
wp_link_pages($post_nav_args);
?>
<?php
// Prevent the direct loading of the file
// ========================================
if(!empty($_SERVER['SCRIPT-FILENAME']) && basename($_SERVER['SCRIPT-FILENAME']) == 'comments.php')
{
die('You cannot access this file directly');
}
?>
<!-- Check if post is pwd protected
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<article class="clearfix">
<header>
<h1><?php the_title(); ?></h1>
<?php if( current_user_can('edit_post', $post->ID)) : ?>
<?php edit_post_link('Edit This', '<p class="article-meta-extra">','</p>'); ?>
<?php endif; ?>
</header>