Last active
August 1, 2016 06:24
-
-
Save avillegasn/7ce9305b0b9b3258004b to your computer and use it in GitHub Desktop.
Entendiendo el Loop de WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( have_posts() ) : | |
while ( have_posts() ) : | |
the_post(); | |
//contenido del loop (template tags, html, etc) | |
endwhile; | |
endif; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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