رفتن به مطلب

نمایش تیترها به صورت تصادفی


پست های پیشنهاد شده

خوب اونی رو که پیدا کردید رو نشون می دادید درستش می کردیم. کد زیر باید جواب بده ...


<ul>
<?php
$args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish', 'offset' => 1);
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

  • امتیاز 3
لینک به ارسال

چون بعد حلقه صفحه تون ازش استفاده می کنید. قبل از کد بالا از کد زیر استفاده کنید. ;)


<?php wp_reset_query(); ?>

  • امتیاز 3
لینک به ارسال

منبع کدی که علی عزیز قرار دادن :

http://codex.wordpress.org/Template_Tags/get_posts#Random_posts

این کد رو هم تست کنید:

<ul>
<?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) { ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php } ?>
</ul>

این کد هم هست:


query_posts(array(
'showposts' => 6,
'orderby' => 'rand',
'category__and' => array(5,8))
));
if (have_posts()) : while (have_posts()) : the_post();
.......

+این کد :

<?php
query_posts(array('orderby' => 'rand', 'showposts' => 5));
if (have_posts()) :
while (have_posts()) : the_post(); ?>

<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

<?php the_content(); ?>

<?php endwhile;
endif; ?>

+این کد :

<ul class="random-posts">
<?php query_posts('showposts=5&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>

  • امتیاز 3
لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...