Hello!
For example, I have the following code in the template file index.php:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <a href="<?php the_permalink(); ?>"> <h2><?php the_title(); ?></h2> </a> <div class="custom"> <?php the_date(); ?> опубликовал <strong><?php the_author(); ?></strong> в рубрике <?php the_category(); ?> <?php the_content(); ?> <a href="<?php the_permalink(); ?>">Читать далее</a> </div> <?php endwhile; ?> 

<? php endif; ?>

It does not matter what the code is, the main thing is that the output from the database is output. So, I want to understand how he does it? For example, I take the the_content () function and try, so to speak, to backtrack in advance how this works. But something I do not understand.

This is how traced, and all

 ./post_templates the_content() get_the_content() ./post.php get_post() class WP_POST ...magic... ./wp_db ...magic.. 

But I did not find the answer, I want to follow in the code straight from connecting to the database until the moment of output to index.php, i.e. How does the whole process of posting go?

Throw a material or in short the entire call stack. What happens inside WP classes? You are welcome!

With WP, it's only the 3rd day, please forgive me if the question is stupid!

Thanks in advance for any answer!

  • call function to output each element ?? mdaaa, WP is a tin - mountpoint
  • In the sense of? And how about 10 more articles, for example, to print without a cycle, but for everyone, the_content () will have to be called for each iteration of the cycle! - pankovalxndr
  • @mountpoint, I recently tried to feed it with PHP Code Sniffer, and the latter seems to be frozen - it hung for four hours in the virtual machine and did not give anything, except errors. - etki

1 answer 1

The have_posts () cycle the_post () refers to the main wordpress query

 global $wp_query 

Posts are in

 $wp_query->posts 

How the_content () displays different content, I will not explain, pure mechanics. I can only say that it is possible for the experiment to take the usual for, inside of which you call

 setup_postdata( WP_Post object ) 

After performing this function, all sorts of

 the_title(), the_content() 

will look at what they slipped into setup_postdata.