<?php $args = array(
'cat' => 4,
'orderby' => 'rand',
'posts_per_page' => 1 // сколько вам нужно рандомных постов
);
$query = new WP_Query($args);
?>
<?php if ($query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<a href="<?php $custom_fields =get_post_custom(); ?>">
<?php the_post_thumbnail(); ?>
<div class="text">
<h2><?php the_title(''); ?></h2>
<p><?php the_content('',true); ?></p>
</div>
</a>
<?php endwhile; ?>
<?php endif; ?>
function custom_search_redirect() {
global $wp_rewrite;
if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {
return;
}
$search_base = $wp_rewrite->search_base;
if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
wp_redirect(home_url("/docs/api/" . urlencode(get_query_var('s'))));
exit();
}
}
add_action('template_redirect', 'custom_search_redirect');
get_template_part('template_parts/main', 'header');
if ( is_front_page() || is_home() ){
// Homepage - начальная статическая страница
get_template_part('template_parts/home', 'page');
} else {
if(get_post_type() == 'post' && is_archive() && !is_author()){
//Список всех записей блога (Blog Archive)
get_template_part('template_parts/blog', 'archive');
}
if(get_post_type() == 'post' && is_single()){
//Одиночная запись блога
get_template_part('template_parts/blog', 'single');
}
//Вариантов вывода может быть множество (смотри документацию):
if(is_page() && !is_search() && !is_page_template() && !is_404()){ }
if(get_post_type() == 'my_custom_post_type_name' && is_single()){ }
if(is_404()){ }
if(is_search()){ }
if (is_archive() && is_author()){ }
if(is_page_template('my_custom_template_name.php')) { }
}
get_template_part('template_parts/main', 'footer');
if ( have_posts() ) : while ( have_posts() ) : the_post();
//В этом цикле выводим посты блога, например:
echo 'Заголовок: ' . get_the_title() . ', текст: ' . get_the_excerpt();
endwhile; else:
_e('Sorry, no posts matched your criteria.');
endif;
//Сбрасываем цикл, если будем запускать повторный цикл с другими параметрами на этой же странице:
wp_reset_query();
while (have_posts()) : the_post();
//Выводим содержание поста:
the_content();
endwhile;
Насколько я знаю, Nginx является веб-сервером для статики, то есть без апача не обойтись?
function new_weather () {
// Выдача из транзитного кэша
$cached = get_transient( 'weather_cache' );
if ( $cached !== false )
return $cached;
$result = simplexml_load_file( 'http://export.yandex.ru/weather-ng/forecasts/27612.xml' );
$temperature = $result->fact->temperature;
// Запись в транзитный кэш на 1 час
set_transient( 'weather_cache', $temperature, 1 * HOUR_IN_SECONDS );
return $temperature;
}
$('.modal-post').click(function(){
var data={
action: 'modal_post_action',
security : CrAjax.security,
id: $(this).data('post')
}
$.post(CrAjax.ajaxurl, data, function(response) {
$('#modal-2 .modal-content').html(response);
});
})
function modal_post_action_callback() {
check_ajax_referer( 'cr-special-ajax', 'security' );
$id = (int) $_POST['id'];
$array = array(
'post_type' => 'collection',
'post__in' => array($id)
);
$query = new WP_Query($array); // можно через get_post();
global $withcomments; // если хотите добавить форму комментариев
$withcomments =1; // для того же
while ( $query->have_posts() ) {
$query->the_post();
// тут цикл
die();
}
add_action( 'wp_ajax_modal_post_action', 'modal_post_action_callback' );
add_action( 'wp_ajax_nopriv_modal_post_action', 'modal_post_action_callback' );