Hallo zusammen
Ich habe in die sidebar.php manuell einen funktioniernden Random Posts Code eingefügt und würde nun gerne wissen, wie man daraus möglichst einfach ein nutzbares Widget erstellt.
Hier mein Code:
PHP
<!-- start a few random posts in the sidebar -->
<ul>
<div id="primary" class="widget-area" role="complementary">
<ul class="xoxo">
<li class="widget-container widget_recent_entries">
<h3 class="widget-title">Beliebte Videos</h3>
<div>
<?php
query_posts(array('orderby' => 'rand', 'showposts' => 15)); //number of shown posts
if (have_posts()) : while (have_posts()) : the_post();
?>
<ul>
<li><a class="widget-img-link" href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><div class="runtime"><?php $key="runtime"; echo get_post_meta($post->ID, $key, true); ?></div><?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) { the_post_thumbnail(array(70,100), array("class" => "widget-img")); } ?></a></li>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<li><span><?php if(function_exists('the_views')) { the_views(); } ?></span></li>
</ul>
<div class="clear"></div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</li>
</ul>
</div>
</ul>
<!-- end our random posts -->
Alles anzeigen