Frage

Ich muss den "klebrigen" Beitrag in einem Abschnitt außerhalb der "Schleife" anzeigen.

Kann mir jemand sagen, wie ich das machen soll?

War es hilfreich?

Lösung

Ich benutze diese Abfrage;

<?php
$sticky = get_option( 'sticky_posts' ); // Get all sticky posts
rsort( $sticky ); // Sort the stickies, latest first
$sticky = array_slice( $sticky, 0, 1 ); // Number of stickies to show
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); // The query

if (have_posts() ) { while ( have_posts() ) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

<?php endwhile;?>
<?php } else { echo ""; }?>

Hoffe es funktioniert auch für dich .. :) :)

Andere Tipps

 $last_sticky_post = get_post(end(get_option('sticky_posts')));
 if(!empty($last_sticky_post)):
   setup_postdata($last_sticky_post);
   the_title(); // standard loop here...
   the_content();
 endif;

(Dies bekommt einen einzelnen Beitrag)

verwenden get_posts () mit dem 'include' => implode(',', get_option('sticky_posts')) Argument, um alle klebrigen Beiträge zu erhalten (Martins Lösung ohne Array_Slice wird dasselbe tun).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top