Skip to content

Instantly share code, notes, and snippets.

@avillegasn
Last active August 1, 2016 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avillegasn/7ce9305b0b9b3258004b to your computer and use it in GitHub Desktop.
Save avillegasn/7ce9305b0b9b3258004b to your computer and use it in GitHub Desktop.
Entendiendo el Loop de WordPress
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
//contenido del loop (template tags, html, etc)
endwhile;
endif;
?>
<?php
/**
* The template for displaying all single posts and attachments
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'single' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// Previous/next post navigation.
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . esc_html__( 'Next', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . esc_html__( 'Next post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . esc_html__( 'Previous', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . esc_html__( 'Previous post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post(); ?>
<div class="entrada">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="contenido">
<?php the_content(); ?>
</div>
</div> <?php
endwhile;
endif;
?>
<?php
$misEntradas = new WP_Query( 'author_name=avillegasn' );
if ( $misEntradas->have_posts() ) :
while ( $misEntradas->have_posts() ):
$misEntradas->the_post();
// renderiza las entradas aquí
endwhile;
endif;
?>
<?php
$args = array(
'post_type' => 'amigo',
'meta_key' => 'edad',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'edad',
'value' => array( 18, 35 ),
'compare' => 'BETWEEN',
),
),
);
$query = new WP_Query( $args );
?>
<?php
query_posts( 'cat=1&tag=temas+plugins' );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// renderiza el contenido aqui (template tags, html, etc)
endwhile;
endif;
?>
<?php
// inicializa la variable global $query_string
global $query_string;
// manten el contenido del Loop original y añade la condicion de un único autor
query_posts( $query_string . "&author_name=avillegasn" );
?>
<?php
$entradas_comunidad = get_posts( 'category_name=comunidad&posts_per_page=5' );
foreach( $entradas_comunidad as $post ) :
setup_postdata( $post ); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1><?php
the_content();
endforeach;
?>
<?php
function mi_funcion_que_filtra_resultados_de_busquedas( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'post_type', 'post' );
}
}
add_action( 'pre_get_posts', 'mi_funcion_que_filtra_resultados_de_busquedas' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment