Hallo,
ich habe folgendes Problem:
Am Ende jeder Artikelseite ist auf meiner Seite eine Auswahl aus drei zufällig ausgewählten Artikeln zu sehen. (Diese werden von Wordpress beim Aufrufen der Seite zufällig ausgewählt - siehe Code)
Das funktioniert auch teilweise alles ganz gut. Zu jedem Artikel erscheint das passende Artikelbild, die passende Überschrift ABER NICHT der passende Textauszug sonder immer ein Textauszug aus dem Artikel der gerade betrachtet wird. Steht also beispielsweise "Heute ist ein schöner Tag" in einem Artikel so wird bei der Vorschau der 3 zufälligen Artikeln am Seitenende überall "Heute ist ein schöner Tag" als Textauszug angezeigt.
Die Vorschau auf die Artikel wird in der single.php via 'content' eingebunden:
single.php:
<?php
get_header(); // Loads the header.php template
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="single-post-content" class="clearfix">
<div id="single-post" class="clearfix">
<header id="post-header">
<h1><?php the_title(); ?></h1>
<ul class="meta clearfix">
<li><strong></strong> </li>
</ul>
</header><!-- /post-header -->
<!-- Entry Content Start -->
<article <?php post_class('entry clearfix fitvids'); ?>>
<div class="inner-post">
<?php the_content(); // This is your main post content output ?>
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$the_tags = array();
foreach($tags as $each_tag) $the_tags[] = $each_tag->term_id;
$args=array(
'tag__in' => $the_tags,
'post__not_in' => array($post->ID),
'showposts' => 5, // Anzahl der aufzulistenden Artikel
'caller_get_posts' => 1 // Verhindert, dass Sticky Posts gelistet werden
);
$new_query = new WP_Query($args);
if( $new_query->have_posts() ) {
echo '<h3>Ähnliche Artikel</h3><ul>'; // Ueberschrift der Liste
while ($new_query->have_posts()) {
$new_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php }
echo '</ul>';
}
}
?>
</div><!-- /inner-post -->
</article><!-- /entry -->
<!-- Entry Content End -->
<?php wp_link_pages(); // Paginate pages when <!- next --> is used ?>
<div class="clearfix">
<?php comments_template(); ?>
<?php
// Get random posts
$wpex_related_posts = get_posts('numberposts=3&orderby=rand&exclude='. $post->ID);
if($wpex_related_posts) { ?>
<section id="related-posts" class="clearfix">
<h2><span><?php _e('Weitere Projekte','wpex'); ?></span></h2>
<div id="entries-wrap" class="clearfix">
<?php
$wpex_count=0;
foreach($wpex_related_posts as $post) :
$wpex_count++;
get_template_part( 'content', get_post_format() ); // get entry
if( $wpex_count == 3 ) { echo '<div class="clear"></div>'; $wpex_count=0; } endforeach; ?>
</div>
<!-- entries-wrap -->
</section><!-- /related-posts -->
<?php } ?>
</div><!-- /clearfix -->
</div><!-- entries-wrap -->
</div><!--/container -->
<?php
//end post loop
endwhile; endif;
//get template footer
get_footer(); ?>
"Content" wird - soweit ich das richtig gesehen habe - in der content.php definidert:
content.php:
<?php
<article <?php post_class('single-entry clearfix'); ?>>
<?php
// Test if post has a featured image
if( has_post_thumbnail() ) {
// Get resize and show featured image : refer to functions/img_defaults.php for default values
$wpex_entry_img = aq_resize( wp_get_attachment_url( get_post_thumbnail_id(), 'full' ), wpex_img( 'blog_entry_width' ), wpex_img( 'blog_entry_height' ), wpex_img( 'blog_entry_crop' ) );
?>
<div class="single-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $wpex_entry_img; ?>" alt="<?php echo the_title(); ?>" /></a>
</div><!-- /single-entry-thumbnail -->
<?php } ?>
<div class="entry-text clearfix">
<header>
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
</header>
<?php
if( !empty($post->post_excerpt) ) {
the_excerpt();
} else {
echo wp_trim_words(get_the_content(), 20); } ?>
</div><!-- /entry-text -->
</article><!-- /single-entry -->
Ich würde mich rießig freuen, wenn mir jemand helfen könnte das Problem mit dem "Textauszug" in den Griff zu bekommen. Zum Abschluss noch eine kleine Grafik des Problems:
Im Voraus schon mal vielen Dank für jede Antwort.