Stie cine cum pot face ca in la sfarsitul fiecarui post sa imi afiseze toate posturile din acea categorie sub forma de link eu am gasit ceva asemanator dar nu e ce caut eu:
Cod PHP:<ul class="linklist">
<?php $recentPosts = new WP_Query();
$recentPosts->query('showposts=12');
while ($recentPosts->have_posts()) : $recentPosts->the_post();
?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title();
?>">
<?php the_title();
?></a> </li>
<?php endwhile;?> </ul>
Ultima modificare făcută de Dennis; 09.03.2011 la 21:33. Motiv: implementare cod BB pentru afisarea corecta a PHP-ului
Este un plugin care face chestia asta, Related Posts.
Fa o pauza si fa niste exercitii pentru abdomen.
Da dar eu as vrea mai mult un cod php
Am testat functia de mai jos si functioneaza ok. Trebuie adaugata in single.php (aici depinde de fiecare tema).
Explicatii:Cod PHP:<h2>Din aceeasi categorie</h2>
<ul>
<?php
$categories = get_the_category();
$args = array( 'numberposts' => 3, 'category' => $categories[0]->cat_ID );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $post ){
echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Citeste '.$post["post_title"].'" >' . $post["post_title"].'</a> </li> ';
}
?>
</ul>
$categories = get_the_category(); - interogheaza toate categoriile corespunzatoare postului curent
$recent_posts = wp_get_recent_posts( $args ); - interogheaza ultimele posturi in functie de arugumente
$args = array( 'numberposts' => 3, 'category' => $categories[0]->cat_ID ); - argumentele
'numberposts' => 3 - cate posturi sa fie afisate
'category' => $categories[0]->cat_ID - categoria din care sa fie afisate posturile
foreach( $recent_posts as $post ){
echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Citeste '.$post["post_title"].'" >' . $post["post_title"].'</a> </li> ';
} - afiseaza titlul si linkurile de la posturile din aceeiasi categorie cu postul curent.
In cazul in care un post e inlcus in mai multe categorii aceasta functie va selecta doar prima categorie si va afisa alte posturi din aceeiasi categorie.
Daca vrei sa afisezi toate posturile din categoria respectiva scoate 'numberposts' => 3 din array. Totusi e bine sa pui o limita (inlocuiesti 3 cu numarul de posturi care doresti sa fie afisate).
Ultima modificare făcută de crt_; 09.03.2011 la 22:25.
Sincer nu merge imi arata doar postul pe care sunt(daca este ultimul iar daca nu imi arata doar urmatorul) pe care sunt si imi apre la comenturi (Comments are closed.)
<?php get_sidebar(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php the_content('<p>Read the rest of this entry »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
<p>
<?php if ( comments_open() && pings_open() ) {
// Both Comments and Pings are open ?>
<?php } elseif ( !comments_open() && pings_open() ) {
// Only Pings are Open ?>
Responses are currently closed, but you can <a href="<?php trackback_url(); ?> " rel="trackback">trackback</a> from your own site.
<?php } elseif ( comments_open() && !pings_open() ) {
// Comments are open, Pings are not ?>
You can skip to the end and leave a response. Pinging is currently not allowed.
<?php } elseif ( !comments_open() && !pings_open() ) {
// Neither Comments, nor Pings are open ?>
Both comments and pings are currently closed.
<?php } edit_post_link('Edit this entry','','.'); ?>
</p>
</div>
Eu l-am pus la sfarsit
Asta este continutul fisierului single.php din tema?
Da, dar este doar php
Stie cineva?