Cum să folosești get_posts() în loc de query_posts() pentru articole personalizate?
În prezent folosesc query_posts
pentru a afișa aceste articole personalizate, dar sunt sigur că ar trebui să folosesc get_posts()
pentru a scrie codul corect.
<?php query_posts( array( 'type-mario' => 'games', 'showposts' => 10 ) ); ?>
<p>Jocuri Mario</p>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Mulțumesc pentru sfaturi.
Salut Elium2009:
Folosind codul tău, cred că asta căutai? (reține că WP_Query()
este doar versiunea mai directă a get_posts()
):
<?php $posts = WP_Query(array(
'taxonomy' => 'type-mario'
'term' => 'games',
'posts_per_page' => 10
)); ?>
<p>Jocuri Mario</p>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Sper că te ajută?

Mulțumesc, dar aș dori să o obțin din taxonomia personalizată asociată postării mele personalizate. Aici, type-mario este taxonomia mea asociată unei postări personalizate, iar games este termenul. Cum ați face asta?

Ai încercat să adaugi taxonomia și termenul în codul de mai sus?<?php query_posts('post_type=games&posts_per_page=10&taxonomy=type_mario&term=games'); ?>
<?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
...
<?php endwhile; endif; ?>
