php - Wordpress posts during the main loop -


while wordpress doing main loop, how determine post belongs current page?

<?php while ( have_posts() ) : the_post(); ?>      <?php         get_template_part( 'template-parts/content', get_post_format() );     ?>  <?php endwhile; ?> 

in above example, how wordpress determine post looped over?

will loop go through posts?

the main query runs every page request. main query makes use of wp_query class fetch posts according parameters set via url structure of page. wp_query works same in main query custom query, diffirence here way how paramteres passed. main query, parameters passed determined url, while custom query parameters manually set user

in short, happens on every single page request made browser

  • the url checked , current permalink structure checked against saved structure in db. if other permalink structure in place in stead of default permalink structure, current permalink structure checked against default structure, , url matched

  • a set of parameters values generated against url , permalink structure. remember, url structure set of $_get variables, $_get variables key/value pair represents parameter/value pair in wp_query. blank parameters still left (there plenty) after others have been filled url filled default values. here instance posts per page set get_option( 'posts_per_page' ) represents amount of posts set in end reading settings.

    in short, far, above says is, if request category page of site, url checked , determined category page. category identified , passed query key/value pair, @ end determine current page must show posts particular category

  • from these parameters , values, sql query build accordingly query database posts according conditions set in sql query. posts returned , stored objects

  • these post objects other important information stored in 1 big object, main query object, stored in $wp_query global variable

up till now, loop has done absolutely nothing. of above happens whether or not have loop on page or not. loop 2 things

  • access main query object , loops through post objects. how these objects send screen determined how html markup, php , css constructed inside loop. loop uses while() loop checks after completion of 1 post if there post display. if there is, while() continues execute, , till no more posts left , kills execution. basic php, sure check how while() loop works

  • the second function loop setting value of $post global. done the_post() call inside loop. on every iteration, $post global set current post being looped though

this basic overview. each process huge , quite difficult understand, , therefor, 1 can never address whole complete process in detail. hope helps


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -