Планирую переезжать на новый сервер. Подскажите какую версию php выбрать 7.0 или 7.1Если Ваш код работает и на той и на другой - я бы выбрал 7.1 по определению. Т.к. она новее и некоторые фреймворки (насколько я помню, Symfony-4 входит в их число) уже требуют версию PHP не ниже 7.1. Т.е. с учётом "с запасом на будущее", я бы взял максимально новую из доступных версий PHP, если Ваш код (проект), который уже написан, на ней запустится.
И какую версию mariaDB - 10.0 или 10.1 ?MariaDB... думаю по тому же принципу. Судя по всему, особо глобальных различий между версий 10.0 и 10.1 нет, но я бы поставил последнюю из этого списка, т.к. судя по всему, её разработчики попытались что-то улучшить (скорее всего, обосновано).
// часовой пояс Москва
$main_timezone = get_option( 'timezone_string', 'Europe/Moscow' );
date_default_timezone_set( "$main_timezone" );
// для даты создания
function main_get_the_date($the_date, $d, $post) {
$d = 'd.m.Y';
$date_now = date_format(date_create("now"), $d);
$date_yesterday = date_format(date_create("yesterday"), $d);
$post = get_post($post);
if ( !$post ) {
return $the_date;
}
$the_date = mysql2date( $d, $post->post_date);
if ($date_now == $the_date) {
$the_date = esc_html__( 'сегодня', 'main' );
} elseif ($date_yesterday == $the_date) {
$the_date = esc_html__( 'вчера', 'main' );
}
return $the_date;
}
add_filter( 'get_the_date', 'main_get_the_date', 10, 3 );
// для даты изменения
function main_get_the_modified_date($the_time, $d) {
$d = 'd.m.Y';
$date_now = date_format(date_create("now"), $d);
$date_yesterday = date_format(date_create("yesterday"), $d);
$the_time = get_post_modified_time($d, null, null, true);
if ($date_now == $the_time) {
$the_time = esc_html__( 'сегодня', 'main' );
} elseif ($date_yesterday == $the_time) {
$the_time = esc_html__( 'вчера', 'main' );
}
return $the_time;
}
add_filter( 'get_the_modified_date', 'main_get_the_modified_date', 10, 2 );
// В functions.php, модифицируем основной запрос:
function modify_my_query( $query ) {
if ( $query->is_main_query() && ! $query->is_admin() ) {
$query->set( 'posts_per_page', 24 );
}
}
add_action( 'pre_get_posts', 'modify_my_query' );
// В самом шаблоне, для изоляции первого поста в стандартном цикле:
if ( have_posts() ) :
while ( have_posts() ) : the_post();
if ( $wp_query->current_post == 0 ) : // Это первый пост в цикле
// вот тут произвольный код для вывода/оформления первого поста
else : // Это все остальные посты
// а тут - для всех остальных
endif;
endwhile;
endif;
<?php if ($related_query->have_posts()):
$i = 0;
?>
<?php while ($related_query->have_posts()) : $related_query->the_post();
$i++;
if ($i > 3) {
break;
}
?>
<li>Здесь миниатюры, тайтлы и т.д.</li>
<?php endwhile; ?>
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site may use a
* different template.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package test
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
the_title(); //Это тайтл самой страницы (если нужен)
the_content(); // это контент страницы, заполенный непосредственно в этой странице в админке (если нужен)
// далее комменты (если надо)
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
<!-- Вот тут уже отдельным лупом - вывод нужных вам постов -->
<?php
// Запускаем отдельный цикл (loop) независимо от контента главной
$args = array (
'post_type' => array( 'post' ),
'post_status' => array( 'publish' ),
'category__in' => array(55,66) // тут category__in - не ошибка. Два андерскора между словами.
);
// The Query
$curstom_query = new WP_Query( $args );
// The Loop
if ( $curstom_query->have_posts() ) {
$postCount = 0;
while ( $curstom_query->have_posts() ) {
$curstom_query->the_post();
// тут делаем что нам надо с постами
$postCount++;
?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php
if($postCount==1){
the_content();
}
else {
the_excerpt();
}
}
} else {
// Тут выводим сообщение о том, что таких постов не найдено (если они реально не найдены)
?>
<h3 class="not-found">Извините. Таких постов не найдено</h3>
<?php
}
// убиваем кастомный луп
wp_reset_postdata();
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();