Отсутствующие никогда не бывают правы (Ф. Рохас).
Показать любое количество постов в цикле
07.08.2016

Время чтения: 1 мин.
Вы когда-нибудь хотели отобразить различное количество постов на разных страницах. Например, на страницах вашей категории, вы хотите бы отобразить 10 постов, которые вы можете управлять с помощью панели администратора, а на другой странице, вы хотите показать только 5 постов. То это руководство как раз для вас.
Открыть файл шаблона, где вы хотите отобразить n-ое количество последних постов:
// if everything is in place and ready, let’s start the loop
// to display ‘n’ number of posts, we need to execute the loop ‘n’ number of times
// so we define a numerical variable called ‘$count’ and set its value to zero
// with each iteration of the loop, the value of ‘$count’ will increase by one
// after the value of ‘$count’ reaches the specified number, the loop will stop
// *USER: change the ‘n’ to the number of posts that you would like to display
if ($count == "n") { break; }
else { ?>
// for CSS styling and layout purposes, we wrap the post content in a div
// we then display the entire post content via the ‘the_content()’ function
// *USER: change to ‘‘ to display post excerpts instead
// here, we continue with the limiting of the number of displayed posts
// each iteration of the loop increases the value of ‘$count’ by one
// the final two lines complete the loop and close the if statementЕсли статья понравилась, то поделитесь ей в социальных сетях:
Подписаться
авторизуйтесь
0 комментариев
Старые