Hallo Forum,
ich suche schon seit Stunden händeringend nach einer Lösung.
Wie oben beschrieben möchte ich unter meinem Artikel alle anderen Artikel der gleichen Kategorie ausgeben.
Das funktioniert mit diesem Schnipsel hier soweit auch super.
<?php
if (is_single()) {
$post_ID = $wp_query->posts[0]->ID;
$all_cats_of_post = get_the_category($post_ID);
$first_cat_ID = $all_cats_of_post[0]->cat_ID;
$first_cat_name = $all_cats_of_post[0]->cat_name;
?>
<ul>
<?php global $post; $cat_posts = get_posts('&category='.$first_cat_ID);
foreach($cat_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
Jetzt will ich aber den aktuellen Artikel NICHT mit anzeigen.
Also definiere ich eine Variable
$id = the_ID();
und füge dann bei get_posts das hier hinzu: 'exclude='.$id.
Zusammen sieht das dann so aus.
<?php
if (is_single()) {
$id = the_ID();
$post_ID = $wp_query->posts[0]->ID;
$all_cats_of_post = get_the_category($post_ID);
$first_cat_ID = $all_cats_of_post[0]->cat_ID;
$first_cat_name = $all_cats_of_post[0]->cat_name;
?>
<ul>
<?php global $post; $cat_posts = get_posts('exclude='.$id.'&category='.$first_cat_ID);
foreach($cat_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
Jetzt bekomme ich aber leider Immernoch ALLE Artikel angezeigt. Zusätzlich noch die ArtikelID des aktuellen Artikels ;-(
Ersetze ich die Variable manuell durch die jeweilige ID funktioniert alles.
Vermutlich hab' ich irgendwo ein einfaches oder doppeltes Anführungszeichen verplant, aber ich komme einfach nicht dahinter ...
Besten Dank vorab.
Marco