Hello, there is a loop that displays blog entries from a specific category, I need to transfer a separate line to a separate div. That is, on the recording page, I create a certain div with no matter what information and I need to somehow throw this div into a cycle. I understand almost nothing in php. Can someone tell me? thank

<?php if ( have_posts() ) : // Ссли ΠΈΠΌΠ΅ΡŽΡ‚ΡΡ записи Π² Π±Π»ΠΎΠ³Π΅. query_posts('cat=7'); // ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ID Ρ€ΡƒΠ±Ρ€ΠΈΠΊ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ вывСсти. while (have_posts()) : the_post(); // запускаСм Ρ†ΠΈΠΊΠ» ΠΎΠ±Ρ…ΠΎΠ΄Π° ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»ΠΎΠ² Π±Π»ΠΎΠ³Π° ?> <div class = "item"> <div class="item_image"><?php the_post_thumbnail(); ?></div> <div class = "item_title"><?php the_title(); ?></div> <div class = "item_excerpt"><?php the_excerpt(10); ?></div> <a href = "<?php the_permalink(); ?>" class = "item_link">ΠŸΠΎΠ΄Ρ€ΠΎΠ±Π½Π΅Π΅</a> </div> <?php endwhile; // Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅ΠΌ Ρ†ΠΈΠΊΠ». endif; /* БбрасываСм настройки Ρ†ΠΈΠΊΠ»Π°. Если Π½ΠΈΠΆΠ΅ ΠΏΠΎ ΠΊΠΎΠ΄Ρƒ Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΠ΄Ρ‚ΠΈ Π΅Ρ‰Π΅ ΠΎΠ΄ΠΈΠ½ Ρ†ΠΈΠΊΠ», Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ Π±Ρ‹Π»ΠΎ сбоя. */ wp_reset_query();?> 
  • Throw out this code and google why you don’t need to use query_posts (and throw a div into a loop, this is all .. get me out from under the table ...) - SeVlad
  • @SeVlad thanks for the helpful comment - Yaroslav Saenko
  • Create any div inside your loop and it will output anyway, no matter what information it contains (static or dynamic). And the question is actually what? - eugene_v
  • Hopefully googled before β€œthank” :) - SeVlad
  • @eugene_v Well, I do not understand how to do it. Well, that is, I created a div (no matter which selector) in the post template and I want this selector to be displayed on a blog page, rather than a separate post - Yaroslav Saenko

1 answer 1

Here I added an abstract custom field to your code:

  <?php if ( have_posts() ) : // Ссли ΠΈΠΌΠ΅ΡŽΡ‚ΡΡ записи Π² Π±Π»ΠΎΠ³Π΅. query_posts('cat=7'); // ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ID Ρ€ΡƒΠ±Ρ€ΠΈΠΊ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ вывСсти. while (have_posts()) : the_post(); // запускаСм Ρ†ΠΈΠΊΠ» ΠΎΠ±Ρ…ΠΎΠ΄Π° ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»ΠΎΠ² Π±Π»ΠΎΠ³Π° ?> <div class="item"> <div class="item_image"><?php the_post_thumbnail(); ?></div> <div class="item_title"><?php the_title(); ?></div> <div class="item_excerpt"><?php the_excerpt(10); ?></div> <div class="custom_field"><?php the_field('custom_field'); ?></div> <a href="<?php the_permalink(); ?>" class = "item_link">ΠŸΠΎΠ΄Ρ€ΠΎΠ±Π½Π΅Π΅</a></div> </div> <?php endwhile; // Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅ΠΌ Ρ†ΠΈΠΊΠ». endif; /* БбрасываСм настройки Ρ†ΠΈΠΊΠ»Π°. Если Π½ΠΈΠΆΠ΅ ΠΏΠΎ ΠΊΠΎΠ΄Ρƒ Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΠ΄Ρ‚ΠΈ Π΅Ρ‰Π΅ ΠΎΠ΄ΠΈΠ½ Ρ†ΠΈΠΊΠ», Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ Π±Ρ‹Π»ΠΎ сбоя. */ wp_reset_query();?> 

What you do not understand here? What you can not do?

  • No query_posts needed here. It is even dangerous. - SeVlad
  • This is another question, now specifically asking how to deduce custom field - eugene_v
  • This is not "another question", but a dangerous answer. - SeVlad
  • And here is a dangerous answer, the person has the written code, I did not impose it on him, I just copied the code and added a line. If you have so much time to comment on every comment, then write a β€œsafe answer”. What a habit and he did not really answer and crap others - eugene_v
  • With that, you need to think about what to write in public. - SeVlad