functions.php açın şunları ekleyin. bu 10 tane rastgele yazı listeler.
function rastgele_yazi($yazi_sayisi="10") {
global $wpdb;
$sorgu = "SELECT ID, post_title, post_status FROM $wpdb->posts where post_status='publish' ORDER BY RAND() LIMIT 0, $yazi_sayisi";
$sonuclar = $wpdb->get_results($sorgu);
foreach ($sonuclar as $sonuc) {
$cikti .= "<li><a href=\"" . get_permalink($sonuc->ID) . "\" title=\"". "\">" . $sonuc->post_title ."</a></li>";
}
echo $cikti;
}Kullanımı:
<?php rastgele_yazi('10'); ?>Eğer siteadresi.com/?rastgele istiyorsanız functions.php dosyasını açın şunları ekleyin:
function yazi_yonlendir() {
global $wpdb;
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_password = '' AND post_status = 'publish' ORDER BY RAND() LIMIT 1";
if ( isset( $_GET['random_cat_id'] ) ) {
$random_cat_id = (int) $_GET['random_cat_id'];
$query = "SELECT DISTINCT ID FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id AND tr.term_taxonomy_id = $random_cat_id) INNER JOIN $wpdb->term_taxonomy AS tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id AND taxonomy = 'category') WHERE post_type = 'post' AND post_password = '' AND post_status = 'publish' ORDER BY RAND() LIMIT 1";
}
if ( isset( $_GET['random_post_type'] ) ) {
$post_type = preg_replace( '|[^a-z]|i', '', $_GET['random_post_type'] );
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = '$post_type' AND post_password = '' AND post_status = 'publish' ORDER BY RAND() LIMIT 1";
}
$random_id = $wpdb->get_var( $query );
wp_redirect( get_permalink( $random_id ) );
exit;
}
if ( isset( $_GET['rastgele'] ) ) {
add_action( 'template_redirect', 'yazi_yonlendir' );
}Kullanımı:
<a href="<?php bloginfo(); ?>/?rastgele">BAS</a>
BAS'a basıldığında rastgele içerik getirir. Tabi html bilginiz ile buna resim eklersiniz js ile zenginleştirirsiniz vsvsvs...
not: fonksiyonları sturkmen'in ücretsiz dağıttığı temalardan aldım...