Ich verwende den folgenden Code, um Beiträge mit verschiedenen Typen und Kategorien zu erhalten, die ihnen zugewiesen sind. Das Problem ist, dass der Hauptbeitrag der Seite verschwunden ist (der, den Sie im Seitenbereich des Administratormenüs schreiben).get_posts funktioniert nicht, aber query_posts tut (Wordpress)
Ich las die Wordpress-Dokumentation und sie sagten, dass ich get_post verwenden sollte, damit es den Hauptbeitrag der Seite nicht stören würde.
Aber jedes Mal ändern ich die alle query_posts
zu get_posts
die Beiträge erscheinen nicht:
<?php get_posts('category_name=Events&showposts=5'); ?>
page-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(); ?>
Danke, ich habe es, das einzige, was mir noch unklar ist, ist die Verwendung der Variablen $ post. Kannst du mir sagen, was nutzt es? (Ist Wordpress kein Standard-Recht?) – alexchenco
@janoChen Das $ post-Objekt enthält Informationen über Wordpress-Posts oder -Seiten. Beachten Sie, dass das globale $ post-Objekt Informationen über die Hauptabfrage enthält (im Falle einer einzelnen Post-Vorlage als single.php), während der lokale $ post in der Schleife über den aktuellen Post Ihrer benutzerdefinierten Abfrage verfügt. In den meisten Fällen müssen Sie nicht mit ihm interagieren, da Sie nur mit Vorlagen-Tags auf diese Informationen zugreifen können. Hier ist eine kurze Referenz: http://www.rlmseo.com/blog/wordpress-post-variable-quick-reference/ – achairapart