mar 162012
 

Do this inside the loop:

<div class="slider-wrapper theme-default">
    <div id="slider" class="nivoSlider"> 
    <?php
        $count = 1;
        $the_query = new WP_Query( array('post_type' => 'post', 'cat' => '10', 'posts_per_page' => '4'));
        while ( $the_query->have_posts() ) : $the_query->the_post();        
        $imageArray = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'noticia_destaque_image2' );
        $imageURL = $imageArray[0]; // here's the image url						
        ?>
        <a href="<?php the_permalink(); ?>"><img src="<?php echo $imageURL; ?>" alt="" title="#htmlcaption<?php echo $count; ?>" /></a>
        <div id="htmlcaption<?php echo $count; ?>" class="nivo-html-caption">
            <strong style="text-transform:uppercase; font-size:13px"><?php the_title(); ?></strong><br />
            <?php the_excerpt(); ?>
        </div>
        <?php $count++; ?>
    <?php endwhile; wp_reset_query(); ?> 
    </div>                   
</div>

But there’s still a little trick you got to do on jquery.nivo.slider.js. Just add the attribute ‘a’ to the children list (line 35):

change this: var kids = slider.children();

for this: var kids = slider.children(‘a’);

mar 132012
 

Lorem ipsum dolor isset

If you want to change the way wordpress set the width for the wp-caption div just go to wp-includes/media.php and change on this line:

return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'

10 to whatever value you need.

Or maybe you want ot try this:

add_filter('shortcode_atts_caption', 'fixExtraCaptionPadding');
 
function fixExtraCaptionPadding($attrs)
{
    if (!empty($attrs['width'])) {
        $attrs['width'] -= 10;
    }
    return $attrs;
}
jul 102011
 
<?php
function geraxml() {
$name = "fulano";
//FILE
$file = "data.xml";
//OPEN FILE
$pointer = fopen($arquivo, "w");
//WRITE ON FILE
fwrite($pointer, "<data>");
fwrite($pointer, "<settings>");
fwrite($pointer, "<width>100%</width><height>100%</height>");
fwrite($pointer, "</settings>");
fwrite($pointer, "<item>");
fwrite($pointer, "<name>".$name."</name>");
fwrite($pointer, "</item>");
fwrite($pointer, "</data>");
//CLOSE FILE
fclose($pointer);
}
add_action("wp_logout", "geraxml");
?>

The file will be created in the root folder. Very useful if you need to create a xml file out of a nextgen gallery to be used by a flash gallery for instance.

jul 102011
 
<?php
get_the_category(); //could be: $post->ID [...]
get_the_title();  //could be: $post->ID, $post->post_parent [...]
get_bloginfo('url');
get_the_content();
get_permalink();
get_the_ID();
get_the_date();
get_the_time();
get_the_author();
get_the_category_list( ', ' );
wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'custom_size_name' );
?>

 

jul 102011
 

m
p
post_parent
subpost
subpost_id
attachment
attachment_id
name
static
pagename
page_id
second
minute
hour
day
monthnum
year
w
category_name
tag
cat
tag_id
author_name
feed
tb
paged
comments_popup
meta_key
meta_value
preview
s
sentence
fields

usage:

<?php $mytag = get_query_var('tag_id'); ?>
jul 102011
 
<?php
$the_query = new WP_Query( array('post_type' => 'post', 'cat' => '10', 'posts_per_page' => 1,'meta_query' => array(array('key' => '_thumbnail_id'))));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<?php the_content(); ?>
<?php endwhile; wp_reset_postdata(); ?>
jul 102011
 

in functions.php

<?php
function wpe_excerptlength_size1($length) {return 20;}  //display 20 words
function wpe_excerptmore($more) {return '...';}
 
function wpe_excerpt($length_callback='', $more_callback='') {
global $post;
if(function_exists($length_callback)){
add_filter('excerpt_length', $length_callback);
}
if(function_exists($more_callback)){
add_filter('excerpt_more', $more_callback);
}
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>'.$output.'</p>';
echo $output;
}
?>

Usage:

<?php wpe_excerpt('wpe_excerptlength_size1', 'wpe_excerptmore'); ?>
jul 102011
 
/* Use the admin_menu action to define the custom boxes */
add_action('admin_menu', 'nyc_boroughs_add_custom_box');
 
/* Adds a custom section to the "side" of the post edit screen */
function nyc_boroughs_add_custom_box() {
add_meta_box('nyc_boroughs', 'Applicable Borough', 'nyc_boroughs_custom_box', 'post', 'side', 'high');
}
 
/* prints the custom field in the new custom post section */
function nyc_boroughs_custom_box() {
//get post meta value
global $post;
$custom = get_post_meta($post->ID,'_nyc_borough',true);
 
// use nonce for verification
echo '<input type="hidden" name="nyc_boroughs_noncename" id="nyc_boroughs_noncename" value="'.wp_create_nonce('nyc-boroughs').'" />';
 
// The actual fields for data entry
echo '<label for="nyc_borough">Borough</label>';
echo '<select name="nyc_borough" id="nyc_borough" size="1">';
 
//lets create an array of boroughs to loop through
$boroughs = array('Manhattan','Brooklyn','Queens','The Bronx','Staten Island');
foreach ($boroughs as $borough) {
echo '<option value="'.$borough.'"';
if ($custom == $borough) echo ' selected="selected"';
echo '>'.$borough.'</option>';
}
 
echo "</select>";
}
 
/* use save_post action to handle data entered */
add_action('save_post', 'nyc_boroughs_save_postdata');
 
/* when the post is saved, save the custom data */
function nyc_boroughs_save_postdata($post_id) {
// verify this with nonce because save_post can be triggered at other times
if (!wp_verify_nonce($_POST['nyc_boroughs_noncename'], 'nyc-boroughs')) return $post_id;
 
// do not save if this is an auto save routine
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
 
$nyc_borough = $_POST['nyc_borough'];
update_post_meta($post_id, '_nyc_borough', $nyc_borough);
}

We can use this field value in our template just as we would embed generic custom fields.

echo get_post_meta($post->ID, '_nyc_borough', true);

jul 102011
 
<?php bloginfo('name'); ?> // Título do blog
<?php wp_title(); ?> // Título do post ou página especí ca
<?php bloginfo('stylesheet_url'); ?> // Localização do arquivo style.css
<?php bloginfo('pingback_url'); ?> // Pingback URL do blog
<?php bloginfo('template_url'); ?> // Localização dos arquivos do tema do blog
<?php bloginfo('version'); ?> // Versão de WordPress do blog
<?php bloginfo('atom_url'); ?> // Atom URL do blog
<?php bloginfo('rss2_url'); ?> // RSS2 URL do blog
<?php bloginfo('url'); ?> // URL do blog
<?php bloginfo('name'); ?> // Nome do blog
<?php bloginfo('html_type'); ?> // Versão HTML do blog
<?php bloginfo('charset'); ?> // Parâmetro da codi cação de caracteres do blog
 
<?php the_content(); ?>    // Conteúdo dos posts
<?php if(have_posts()) : ?> // Checar se tem posts
<?php while(have_posts()) : the_post(); ?> // Mostra posts se posts estão disponíveis
<?php endwhile; ?> // Fecha a função PHP 'while'
<?php endif; ?> // Fecha a função PHP 'if'
<?php get_header(); ?> // Conteúdo do header.php
<?php get_sidebar(); ?> // Conteúdo do sidebar.php
<?php get_footer(); ?> // Conteúdo do footer.php
<?php the_time('m-d-y') ?> // A data em formato '08-18-07'
<?php comments_popup_link(); ?> // Link para os comentários do post
<?php the_title(); ?> //    Título de um post ou página especí ca
<?php the_permalink() ?> // URL de um post ou página especí ca
<?php the_category(', ') ?> // Categoria de um post ou página especí ca
<?php the_author(); ?> // Autor de um post ou página especí ca
<?php the_ID(); ?> // ID de um post ou página especí ca
<?php edit_post_link(); ?> // Link para editar um post ou página especí cas
<?php get_links_list(); ?> // Links do blogroll
<?php comments_template(); ?> // Conteúdo do comment.php
<?php wp_list_pages(); ?> // Lista de páginas do blog
<?php wp_list_cats(); ?> // Lista de categorias do blog
<?php next_post_link(' %link ') ?> // URL do próximo post
<?php previous_post_link('%link') ?> // URL do post anterior
<?php get_calendar(); ?> // O calendário embutido
<?php wp_get_archives() ?> // Lista de arquivos do blog
<?php posts_nav_link(); ?> // Links do próximo post e do post anterior
<?php bloginfo(’description’); ?> // Descrição do site
 
/%postname%/   //Permalinks customizados
<?php include(TEMPLATEPATH ./x’); ?> // Inclua qualquer arquivo1
<?php the_search_query(); ?> // Valor para o formulário de buscar.
<?php _e(’Message’); ?> // Mostra uma mensagem
<?php wp_register(); ?> // Mostra o link de registração
<?php wp_loginout(); ?> // Mostra o link de login/logout
<!--next page--> // Divide o conteúdo em páginas
<!--more--> // Corta o conteúdo e adiciona um link para o resto do conteúdo
<?php wp_meta(); ?> // Meta para administradores
<?php timer_stop(1); ?> // Tempo para carregar a página
<?php echo get_num_queries(); ?> //Queries para carregar a página
jul 042011
 

In wp-blog-header.php add:

<?php
if ( !isset($wp_did_header) ) {
 
$wp_did_header = true;
 
require_once( dirname(__FILE__) . '/wp-load.php' );
 
if(current_user_can('level_10')){
	wp();
	require_once( ABSPATH . WPINC . '/template-loader.php' );
} 
}
?>

Levels:

Subscriber : level_0
Contributor: level_1
Author: level_2
Editor: level_3 – level_7
Administrator: level_8 – level_10

jul 012011
 

In the page:

<table>
<tr>
<td colspan="2" align="center">
<input value="Nome" title="Nome" id="nome" type="text" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input value="E-mail" title="E-mail" id="email" type="text" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<textarea id="mensagem" title="Mensagem">Mensagem</textarea>
</td>
</tr>
<tr>
<td align="left" valign="top">
<span class="errms">&nbsp;</span>
<span id="loading">Enviando...</span>
</td>
<td width="93"><a class="btn-enviar">Enviar</a></td>
</tr>
</table>

<script type="text/javascript">
$(document).ready(function(){
$('.btn-enviar').click(function() {
var nome = $('#nome').val();
var email = $('#email').val();
var mensagem = $('#mensagem').val();
getstr = "nome="+nome+"&email="+email+"&mensagem="+mensagem;
var content_ready = encodeURI(getstr);
if(nome == "" || nome == "Nome"){$('.errms').text("Favor inserir o nome.");}
else if(email == "" || email == "E-mail"){$('.errms').text("Favor inserir o e-mail.");}
else if(email.indexOf("@") == -1 || email.indexOf(".") == -1) {$('.errms').text("E-mail incorreto.");}
else if(mensagem == "" || mensagem == "Mensagem"){$('.errms').text("Favor inserir a mensagem.");}
else {
$.ajax({
type: "post",url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",data: "action=sendmail&"+content_ready,
beforeSend: function(){$('.errms').text(""); $("#loading").fadeIn('1000');},
success: function(html){
$("#form-content").html(html);
}
}); //close $.ajax(*/
}
}); //close click(
}); //close $(
</script>

 

In functions.php

<?php
function implement_ajax() {
if(isset($_POST['nome']) && isset($_POST['mensagem']) && isset($_POST['email']))
{
$success = false;
function cleanstr($str){
return preg_replace('/<(.*)\s+(\w+=.*?)>/', '', $str);
}
$mensagem = isset($_POST['mensagem']) ? cleanstr($_POST['mensagem']):"";
$nome = isset($_POST['nome']) ? cleanstr($_POST['nome']):"";
$email = isset($_POST['email']) ? cleanstr($_POST['email']):"";
 
// sending
$to = "address@gmail.com";
$subject = "Contato site";
$message = "
<html>
<body>
<p>$mensagem</p>
<p>$nome<br />$email<br />
</body>
</html>
";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "From: $nome <$email>\n";
$headers .= "Bcc: bccaddress@gmail.com\n";
$headers .= "Return-Path: $email\n";
// send email
if($mensagem != "" && $nome != "" && $email != ""){
if(!mail($to, $subject, $message, $headers ,"-r t.diezel@peppernet.com.br")){ // Se for Postfix
$headers .= "Return-Path: t.diezel@peppernet.com.br\n"; // Se "não for Postfix"
$success = mail($to, $subject, $message, $headers );
} else {
$success = true;
}
}
 
 
// redirect to success page
if ($success){
echo '<span>Sua mensagem foi enviada. Agradecemos o contato.</span><br /><br />';
}
else{
echo '<span>Houve um erro ao enviar a mensagem. Favor tentar novamente mais tarde.</span>';
}
}
die();
}
add_action('wp_ajax_sendmail', 'implement_ajax');
add_action('wp_ajax_nopriv_sendmail', 'implement_ajax');//for users that are not logged in.
?>