Skip to content

Instantly share code, notes, and snippets.

View babelpuntocl's full-sized avatar
🤖

babel.cl babelpuntocl

🤖
View GitHub Profile
// Primer loop
<?php $sticky = get_option('sticky_posts'); rsort( $sticky ); $sticky = array_slice( $sticky, 0, 5); query_posts( array( 'post__in' => $sticky,'caller_get_posts' => 1 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//contenido
<?php endwhile; endif; wp_reset_query(); ?>
// Segundo loop
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $no_sticky_args = array('post__not_in' => get_option('sticky_posts'), 'paged' => $paged ); query_posts($no_sticky_args); ?>
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
<?php $nombre_variable = get_post_meta($post->ID, 'nombre_cf', true); if ($nombre_variable) { ?>
<?php the_field('nombre_cf'); ?>
<?php } else { ?>
//mostrar esto
<?php } ?>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('servicio', array('class' => 'nombre_clase'));
} else { ?>
<img src="http://placehold.it/475x266/" />
<?php } ?>
@babelpuntocl
babelpuntocl / new_gist_file.php
Created April 22, 2014 14:20
Dos loops con sticky Post
// Primer loop
<?php $sticky = get_option('sticky_posts'); rsort( $sticky ); $sticky = array_slice( $sticky, 0, 5); query_posts( array( 'post__in' => $sticky,'caller_get_posts' => 1 ) ); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//contenido
<?php endwhile; endif; wp_reset_query(); ?>
// Segundo loop
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $no_sticky_args = array('post__not_in' => get_option('sticky_posts'), 'paged' => $paged ); query_posts($no_sticky_args); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//contenido
<?php endwhile; endif; wp_reset_query(); ?>
@babelpuntocl
babelpuntocl / excerpts.php
Created April 22, 2014 14:23
Excerpts personalizados
function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); return $excerpt; } function content($limit) { $content = explode(' ', get_the_content(), $limit); if (count($content)>=$limit) { array_pop($content); $content = implode(" ",$content).'...'; } else { $content = implode(" ",$content); } $content = preg_replace('/\[.+\]/','', $content); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); return $content; }
<?php echo excerpt(25); ?>
// Add ID and CLASS attributes to the first <ul> occurence in wp_page_menu
function add_menuclass( $ulclass ) {
return preg_replace( '/<ul>/', '<ul id="nav" class="something-classy">', $ulclass, 1 );
}
add_filter( 'wp_page_menu', 'add_menuclass' );
// Add Your Menu Locations
function register_my_menus() {
register_nav_menus(
array(
'header_navigation' => __( 'Header Navigation' ),
'expanded_footer' => __( 'Expanded Footer' )
)
);
}
add_action( 'init', 'register_my_menus' );
<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
'category_name' => 'tutorials',
'posts_per_page' => 5,
'paged' => $paged
);
// create a new instance of WP_Query
Dirección repositorio: https://[email protected]/thetitan/sourcecodedna.git.