Afisează toate articolele din categoria curentă
27 oct. 2012, 09:39:27
Vizualizări: 15.2K
Voturi: 1
Încerc să creez un comportament asemănător cu cel din următorul link:
http://www.javaexperience.com/java-role-of-serialversionuid-in-serialization/
Aici sunt afișate toate articolele din aceeași categorie. În prezent, acesta este cod HTML scris manual, eu doresc să reproduc acest comportament folosind cod PHP în single.php.
Mai jos este codul pe care l-am scris până acum:
<?php
$category = get_the_category(); // Obține categoria curentă
<ul>
query_posts('cat='.$category); // Interoghează postările din categorie
if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="<?php echo get_permalink( $id ); ?>"><?php the_title(); ?></a></li>
endwhile; endif;
</ul>
<br/>
?>
Poate cineva să mă ajute să-l fac funcțional?
Toate răspunsurile la întrebare
2
1
Încearcă acest cod:
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
$PozCat->id // ne oferă ID-ul categoriei curente.
Apoi folosește acest hook în interogarea ta:
<ul>
<?php
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
//$PozCat->id
query_posts('posts_per_page=-1&cat='.$PozCat->id);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>

Fatih Toprak
255
27 oct. 2012 11:48:55
0
Puteți face acest lucru folosind Wp_query() prin transmiterea numelui categoriei ca argument:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>

swtshweta
432
27 oct. 2012 11:36:27
Întrebări similare
2
răspunsuri
3
răspunsuri