Suport » Module și hacking » help me radomize the posts
help me radomize the posts
-
<?php $counter = 0; $counter2 = 0; while (have_posts()) : the_post(); ?> <?php $counter++; $counter2++; ?> <div class="grid_6 <?php if ($counter == 1) { echo 'alpha'; } else { echo 'omega'; $counter = 0; } ?>">
mă poate ajuta cineva să modific php-ul de mai sus ca să-mi afișeze posturile random
PS: știu de wordpress codex doar că nu știu să implementez
mulțumesc
-
Unde dorsti sa le afisezi?
Si ce din postari?
codul de mai sus este din index.php tot acolo vreau să le afișez random și posturile să fie din toate categoriile
mulțumesc
Tot continutul,ori doar titlul?
<?php $post_id = get_the_ID(); $args = array( 'orderby' => 'rand', 'posts_per_page' => 5, 'post__not_in' => array( $post_id ) ); $rand_query = new WP_Query( $args ); echo '<ul>'; while ( $rand_query->have_posts() ) : $rand_query->the_post(); echo '<li><a href="' . get_permalink() . '" title="' . the_title_attribute() . '">' . the_title() . '</a></li>'; endwhile; echo '</ul>'; ?>
Salut,
Incearca codul asta, nu am facut teste, asa ca fa o copie la fisierul care il editezi.
numberpost – cate posturi sa-ti apara.
category – din ce categorie sa apara posturile.<?php $args = array( 'numberposts' => 2, 'offset'=> 1, 'category' => 1 ); $counter = 0; $counter2 = 0; foreach( $rand_posts as $post ) : ?> <?php $counter++; $counter2++; ?> <div class="grid_6 <?php if ($counter == 1) { echo 'alpha'; } else { echo 'omega'; $counter = 0; } ?>">
nu merge nici o variantă, probabil din cauză am v-am arătat doar o parte din cod
cum ambele soluții îmi apare asta
Server error The website encountered an error while retrieving http://xxxxxxxxxx.ro/. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
here we go with whole index.php
<?php get_header(); ?> <div id="content" class="fullspan"> <div class="container_16 clearfix"> <div id="leftcontent" class="grid_12"> <div class="large-screenshot"> <div class="large-screenimg"> <?php if(function_exists('vslider')){ vslider('vslider_options'); } ?> </div><!-- /screenimg --> </div><!-- /screenshot--> <?php $counter = 0; $counter2 = 0; while (have_posts()) : the_post(); ?> <?php $counter++; $counter2++; ?> <div class="grid_6 <?php if ($counter == 1) { echo 'alpha'; } else { echo 'omega'; $counter = 0; } ?>"> <div class="post"> <div class="screenshot"> <div class="screenimg"> <?php if ( get_option('woo_layout') == '1-photo.php' ) { ?> <?php if ( get_option('woo_resize') ) { woo_get_image('large-image','330','190'); } else { ?> <a href="<?php the_permalink() ?>" title="View <?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a> <?php } ?> <?php } else { ?> <?php if ( get_option('woo_resize') ) { woo_get_image('large-image','330','190','url'); } else { ?> <a href="<?php echo get_post_meta($post->ID, "url", $single = true); ?>" target="_blank" title="View <?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a> <?php } ?> <?php } ?> <span><?php the_category(','); ?></span> </div> </div> <div class="theme"> <div class="grid_4 alpha"><h2><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2></div> <div class="grid_2 omega"><p class="date"><strong><?php _e('De la',woothemes); ?> <?php the_field('15-29_zile'); ?> €/zi</strong></p></div> <div style="clear:both;"></div> <div class="grid_4 alpha"><p class="tags"><?php the_tags('', ', ' , ''); ?></p></div> <div class="grid_2 omega" style="text-align:right;"><?php if(function_exists('the_ratings')) { the_ratings(); } ?> </div> <div style="clear:both;"></div> </div> </div><!-- /post --> <div style="clear:both;height:10px;"></div> </div> <?php if ( $counter == 0 ) { ?><div style="clear:both;height:0px;"></div><?php } ?> <?php endwhile; ?> <div style="clear:both;height:0px;"></div> <div id="postnav"> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> </div><!-- /postnav --> </div><!-- /leftcontent --> <?php get_sidebar(); ?> </div><!-- /container_16 --> </div><!-- /content --> <?php get_footer(); ?>
vreau să afișez posturi din toate categoriile random
vroiam să afișez random posturile de la tema snapshop/woothemes
rezolvarea:
/wp-content/themes/snapshot/index.php – linia 21$args = array( 'orderby' => 'rand' ); global $wp_query; $wp_query = new WP_Query( $args );
- Subiectul „help me radomize the posts” este închis pentru răspunsuri noi.