Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
THE LOOP
        JAKE SPURLOCK
@WHYISJAKE JAKESPURLOCK.COM
DEVELOPERS IN
 THE HOUSE?
OVERVIEW


INTRODUCE THE LOOP

BASIC TEMPLATE TAGS

CUSTOM QUERIES

MULTIPLE LOOPS PAGE

CUSTOM POST TYPES
GET STARTED...
WHY NOT JUST LOOK AT CODE EH?
SIMPLEST INDEX PAGE

<?PHP

     IF (HAVE_POSTS()) :

       WHILE (HAVE_POSTS()) :

          THE_POST();

          THE_...
TEMPLATE TAGS
.:THE BREAD AND BUTTER OF THEME DESIGNERS:.
TEMPLATE TAGS

THE_CONTENT()         THE_META();

THE_TITLE()           THE_ID()

THE_PERMALINK()       THE_POST_THUMBNAIL...
CUSTOM QUERIES
QUERY_POSTS
    VS.
 GET_POSTS
QUERY_POSTS



WHEN YOU WANT TO CHANGE THE MAIN LOOP

EXCLUDE CATEGORIES FROM MAIN LOOP

SHOW POSTS FROM ONLY ONE CATEGORY.
IMPORTANT NOTE

THE QUERY_POSTS FUNCTION IS INTENDED TO BE USED
TO MODIFY THE MAIN PAGE LOOP ONLY. IT IS NOT
INTENDED AS A...
<?php

//The
Query
query_posts('posts_per_page=5');

//The
Loop
if
(
have_posts()
)
:
while
(
have_posts()
)
:

the_post()...
CUSTOM POST TYPES?
QUERY_POSTS WITH
       CUSTOM POST TYPES



QUERY_POSTS( 'POST_TYPE=NAME 0F POST TYPE');

QUERY_POSTS(ARRAY('POST_TYPE' =...
PLUGIN?

ADD_FILTER( 'PRE_GET_POSTS', 'MY_GET_POSTS' );

FUNCTION MY_GET_POSTS( $QUERY ) {

!  IF ( IS_HOME() && FALSE == ...
THE LOOP
        JAKE SPURLOCK
@WHYISJAKE JAKESPURLOCK.COM
Próxima SlideShare
Cargando en…5
×

WordCamp 2010 The WordPress Loop

2.230 visualizaciones

Publicado el

Learn about custom queries, template tags, and more!

Publicado en: Diseño
  • Sé el primero en comentar

WordCamp 2010 The WordPress Loop

  1. 1. THE LOOP JAKE SPURLOCK @WHYISJAKE JAKESPURLOCK.COM
  2. 2. DEVELOPERS IN THE HOUSE?
  3. 3. OVERVIEW INTRODUCE THE LOOP BASIC TEMPLATE TAGS CUSTOM QUERIES MULTIPLE LOOPS PAGE CUSTOM POST TYPES
  4. 4. GET STARTED... WHY NOT JUST LOOK AT CODE EH?
  5. 5. SIMPLEST INDEX PAGE <?PHP IF (HAVE_POSTS()) : WHILE (HAVE_POSTS()) : THE_POST(); THE_CONTENT(); ENDWHILE; ENDIF; ?>
  6. 6. TEMPLATE TAGS .:THE BREAD AND BUTTER OF THEME DESIGNERS:.
  7. 7. TEMPLATE TAGS THE_CONTENT() THE_META(); THE_TITLE() THE_ID() THE_PERMALINK() THE_POST_THUMBNAIL() THE_CATEGORY() THE_AUTHOR() THE_TAGS() THE_SHORTLINK() THE_DATE() EDIT_POST_LINK() CODEX.WORDPRESS.ORG/TEMPLATE_TAGS THE_EXCERPT()
  8. 8. CUSTOM QUERIES
  9. 9. QUERY_POSTS VS. GET_POSTS
  10. 10. QUERY_POSTS WHEN YOU WANT TO CHANGE THE MAIN LOOP EXCLUDE CATEGORIES FROM MAIN LOOP SHOW POSTS FROM ONLY ONE CATEGORY.
  11. 11. IMPORTANT NOTE THE QUERY_POSTS FUNCTION IS INTENDED TO BE USED TO MODIFY THE MAIN PAGE LOOP ONLY. IT IS NOT INTENDED AS A MEANS TO CREATE SECONDARY LOOPS ON THE PAGE. IF YOU WANT TO CREATE SEPARATE LOOPS OUTSIDE OF THE MAIN ONE, YOU SHOULD USE GET_POSTS() INSTEAD. USE OF QUERY_POSTS ON LOOPS OTHER THAN THE MAIN ONE CAN RESULT IN YOUR MAIN LOOP BECOMING INCORRECT AND POSSIBLY DISPLAYING THINGS THAT YOU WERE NOT EXPECTING. THE QUERY_POSTS FUNCTION OVERRIDES AND REPLACES THE MAIN QUERY FOR THE PAGE. TO SAVE YOUR SANITY, DO NOT USE IT FOR ANY OTHER PURPOSE.
  12. 12. <?php //The
Query query_posts('posts_per_page=5'); //The
Loop if
(
have_posts()
)
:
while
(
have_posts()
)
:
 the_post(); 
.. endwhile;
else: 
.. endif; //Reset
Query wp_reset_query(); ?>
  13. 13. CUSTOM POST TYPES?
  14. 14. QUERY_POSTS WITH CUSTOM POST TYPES QUERY_POSTS( 'POST_TYPE=NAME 0F POST TYPE'); QUERY_POSTS(ARRAY('POST_TYPE' => ARRAY('POST', 'MOVIES')));
  15. 15. PLUGIN? ADD_FILTER( 'PRE_GET_POSTS', 'MY_GET_POSTS' ); FUNCTION MY_GET_POSTS( $QUERY ) { ! IF ( IS_HOME() && FALSE == $QUERY- >QUERY_VARS['SUPPRESS_FILTERS'] ) ! ! $QUERY->SET( 'POST_TYPE', ARRAY( 'POST', 'PAGE', 'ALBUM', 'MOVIE', 'QUOTE', 'ATTACHMENT' ) ); ! RETURN $QUERY; } VIA
JUSTIN
TADLOCK
  16. 16. THE LOOP JAKE SPURLOCK @WHYISJAKE JAKESPURLOCK.COM

×