Я использую следующий код для получения сообщений с разными типами и категориями, назначенными им. Проблема в том, что основная страница страницы исчезла (та, которую вы пишете в разделе страницы меню администратора).get_posts не работает, но query_posts делает (Wordpress)
Я читал документацию Wordpress, и они сказали, что я должен использовать get_post, чтобы он не мешал основному сообщению страницы.
Но каждый раз, когда я меняю не появляются все query_posts
к get_posts
посты:
<?php get_posts('category_name=Events&showposts=5'); ?>
страниц events.php:
<?php
/**
* Template Name: Events Template
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php // find all content that has the category of Events and then to loop through them. ?>
<?php query_posts('category_name=Events&showposts=5'); ?>
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (is_front_page()) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="page-link">' . __('Pages:', 'twentyten'), 'after' => '</div>')); ?>
<?php edit_post_link(__('Edit', 'twentyten'), '<span class="edit-link">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php comments_template('', true); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #container -->
<div id="container">
<div id="content" role="main">
<?php // find all content that has the type of video and then to loop through them. ?>
<?php query_posts(array('post_type'=>'video')); ?>
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (is_front_page()) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="page-link">' . __('Pages:', 'twentyten'), 'after' => '</div>')); ?>
<?php edit_post_link(__('Edit', 'twentyten'), '<span class="edit-link">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php comments_template('', true); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Спасибо, я понял, единственное, что до сих пор неясно, - это использование переменной '$ post'. Можете ли вы рассказать мне, в чем его польза? (не является правильным по умолчанию для Wordpress?) – alexchenco
@janoChen Объект $ post содержит информацию о сообщениях Wordpress или страницах. Обратите внимание, что глобальный объект $ post содержит информацию об основном запросе (в случае одного шаблона сообщения, как single.php), в то время как локальный столбец $ в цикле относится к текущему сообщению вашего пользовательского запроса. В большинстве случаев вам не нужно взаимодействовать с ним, потому что вы можете получить доступ к этой информации только с помощью тегов шаблонов. Вот краткая ссылка: http://www.rlmseo.com/blog/wordpress-post-variable-quick-reference/ – achairapart