Skip to content

Instantly share code, notes, and snippets.

@CEscorcio
CEscorcio / Loop sub menu
Last active December 17, 2015 19:58
Imprimir os sub menus apenas das categorias em questão.
<?php
$children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul id="subnav">
<?php echo $children; ?>
</ul>
<?php } ?>
OR
@CEscorcio
CEscorcio / class name widget
Created May 29, 2013 12:26
add a custom class for a wordpress widget
/**
* add class to widget
*
*
*/
function kc_widget_form_extend( $instance, $widget ) {
if ( !isset($instance['classes']) )
$instance['classes'] = null;
@CEscorcio
CEscorcio / page name to body class
Created May 29, 2013 14:26
Adicionar o nome da página na class da página.
function add_body_class( $classes )
{
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_body_class' );
@CEscorcio
CEscorcio / latest
Created June 17, 2013 15:32
get latest posts
<ul>
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<span class="latestpostmeta"><?php the_time('M jS, Y') ?> </span></li>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<li><?php the_excerpt(__('(more…)')); ?></li>
<?php the_post_thumbnail(); ?>
<?php endwhile;?>
</ul>
@CEscorcio
CEscorcio / excerpt
Created June 17, 2013 16:52
Limit excerpt and change read more text
functions.php
function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = '<p>'.$excerpt.'... </br><a href="'.$permalink.'">Read more more</a></p>';
return $excerpt;
@CEscorcio
CEscorcio / Featured Posts
Created June 17, 2013 18:15
Featured posts in Wordpress *** cat1= category that will echo
@CEscorcio
CEscorcio / deploy
Created June 25, 2013 08:15
deploy to bitbucket
<?php
// Set these dependant on your BB credentials
$username = 'username';
$password = 'password';
$branch = 'master';
// FTP Credentials
@CEscorcio
CEscorcio / wordpress
Created June 26, 2013 19:35
last 3 posts with thumb
<ul>
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_excerpt(__('(more…)')); ?></li>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail( array(100,100) );
} ?>
<?php endwhile;?>
</ul>
@CEscorcio
CEscorcio / exclude cat
Created July 9, 2013 17:11
Exlude category from loop
<?php
$args=array(
'category__not_in' => array(8),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
@CEscorcio
CEscorcio / post == title page
Created July 18, 2013 14:18
lists posts from a category that has the same name as the page.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>