function zufalls_artikel_shortcode( $atts ) {
$atts = shortcode_atts( array(
'anzahl' => 5,
'bild' => 'medium', // Bildgröße: thumbnail, medium, large oder "nein"
), $atts );
$query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => intval( $atts['anzahl'] ),
'orderby' => 'rand',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
) );
if ( ! $query->have_posts() ) return '';
$out = '- ';
while ( $query->have_posts() ) {
$query->the_post();
$link = esc_url( get_permalink() );
$out .= '
- '; if ( $atts['bild'] !== 'nein' && has_post_thumbnail() ) { $out .= '' . get_the_post_thumbnail( null, sanitize_key( $atts['bild'] ), array( 'loading' => 'lazy', 'alt' => esc_attr( get_the_title() ) ) ) . ''; } $out .= '' . esc_html( get_the_title() ) . ''; $out .= ' '; } wp_reset_postdata(); return $out . '
[zufalls_artikel anzahl=“5″] zeigt kleine Vorschaubilder (Größe „medium“).
[zufalls_artikel bild=“nein“] zeigt wie bisher nur die Titel.
.zufalls-artikel {
list-style: none;
margin: 0;
padding: 0;
}
.zufalls-artikel li {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 12px;
}
.zufalls-artikel-bild img {
width: 70px;
height: 70px;
object-fit: cover;
border-radius: 4px;
display: block;
}

