Results 1 to 3 of 3

Thread: Random 5 Sticky posts in index.php

  1. #1
    Thread Starter
    Junior Member
    Not a Verified Customer
    xiscomax's Avatar
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Random 5 Sticky posts in index.php

    Hello as displayed in index.php, only 5 sticky posts at random?

  2. #2
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random 5 Sticky posts in index.php

    Code:
    <?php
    $sticky = get_option( 'sticky_posts' );
    query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1, 'orderby' => rand, 'showposts' => 5 ) );  ?>
    You'd have to work something like that into the loop

  3. #3
    Thread Starter
    Junior Member
    Not a Verified Customer
    xiscomax's Avatar
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: Random 5 Sticky posts in index.php

    Quote Originally Posted by Damien
    Code:
    <?php
    $sticky = get_option( 'sticky_posts' );
    query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1, 'orderby' => rand, 'showposts' => 5 ) );  ?>
    You'd have to work something like that into the loop

    Thank you very much for the quick response, my knowledge of php are scarce.
    this is my index.php code to integrate your code?

    Code:
    <?php
    require_once dirname( __FILE__ ) . '/form_process.php';
    get_header( ); 
    include_classified_form( );
    ?>
    <link href="styles/blue.css" rel="stylesheet" type="text/css" />
    
    
    	<div class="content">
    	
    
    	
    		<ul id="catnav">
                <li<?php if ( is_home() ) { echo " class=\"current-cat\""; } ?>><?php _e('Latest Listings','cp'); ?>
    			<?php wp_list_categories('show_count=0&hide_empty=true&orderby=name&order=asc&title_li='); ?>
    			[*]<div class="clear"></div>[/list]
    		
    		<?php if ( is_category() && function_exists('bcn_display')) { ?>	
    			<div class="subnav">
    				<?php if(function_exists('bcn_display')) { bcn_display(); } ?>
    			</div>
    		<?php } ?>
    		
    		<div class="main">
    		
    			<div class="listing">
    				<div class="head">
    				
    				<span class="price">
    					<?php _e('Price','cp'); ?>
    					[img]<?php bloginfo('template_url'); ?>/images/sortup.gif[/img][img]<?php bloginfo('template_url'); ?>/images/sortdown.gif[/img]					</span>
    				<?php echo 'Actualmente hay ' . $numposts . ' anuncios' . ' ,distribuidos en ' . $numcats . ' categorias.';?>
    				<div class="clear"></div>  
    			  </div>
    			  
    				<div class="list">
    					<?php 
    					$i = 1; 
    					
    					if(!empty($_GET['sort']))
    					{
    					$orderby=trim($_GET['sort']);
    					$order=trim($_GET['order']);
    					$key=trim($_GET['key']);
    					
    					
    					// create the sort by injection
    					$posts = query_posts($query_string . '&orderby='.$orderby.'&meta_key='.$key.'&order='.$order.'');
    					}
    					
    					if (have_posts()) : ?>
    					
    					<?php while (have_posts()) : the_post(); ?>
    					
    					<?php if ($i % 2 == 0) { $alt = " class=\"alt\""; } else { $alt = " class=\"no\""; } echo "<div" . $alt;
    					if (is_sticky()) { echo " id='sticky' "; } echo ">"; 
    					?>				
    						
    				  <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    									
    					<?php if ( get_option('main_page_img') != "no" ) { ?>
    					
                      <span class="date"><div><?php the_time(get_option('date_format')) ?></div>
    				  <?php the_time(get_option('time_format')) ?></span>	
    			
    
    						<span class="image">	
    							<?php $images = get_post_meta($post->ID, "images", true);
    								if (empty($images)) {?>
    								    <div class="main_page_no_img">[img]<?php bloginfo('template_url'); ?>/images/no-pic.png[/img]</div></span>
    								<?php } else { ?>
    								<div class="main_page_img" style="background: transparent url(<?php echo get_bloginfo('template_url')."/includes/img_resize.php?width=90&height=70&url=";?><?php
    										  if ( strstr($images, ',')) {  
    											$matches = explode(",", $images);
    											$img_single = $matches[0];
    											$img_single = explode(trailingsla****(get_option('siteurl')) . "wp-content/uploads/classipress/", $img_single);
    											echo $img_single[1];
    										  } else {
    											$img_single2 = $images;
    											echo $img_single2;
    												}?>) no-repeat"></div></span>
    								<?php 
    								} 
    									} else {
    										$ii = 1;
    										echo "<span class='cat_image'>";
    										foreach((get_the_category()) as $category) {
    											if ($ii == "1") {
    												$cat_image = get_bloginfo('template_url')."/images/category-icons/".get_option("cat$category->cat_ID").".png";
    												echo "[img] . $cat_image . [/img]";
    												$ii++;
    											}
    										}
    										echo "</span>";
    									} ?>
    								
    				  <span class="item">
    				  <div class="titulo"><?php if ( strlen(get_the_title()) > 65 ) { echo substr(get_the_title(), 0, 65)."..."; } else { the_title(); } ?>
    				  </div>
    				  <span class="contenido"><?php echo substr(strip_tags($post->post_content), 0, 100)."...";?></span>
    				   
                      <div class="precio"><?php echo get_post_meta($post->ID, "price", true); ?> <?php echo get_option('currency'); ?></div></span></a>
    				 
    				 <div class="clear"></div>
    			  </div>
    						
    					<?php $i++; unset($alt); ?>
    					
    					<?php endwhile; ?>
    					
    
    						<div class="navigation1">
    						<div class="navigation2">
    						
    						<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else {  ?>
    						
    							<div class="alignleft">
    								<?php next_posts_link('<div class="next_post_link"></div>') ?>
    							</div>
    							<div class="alignright">
    								<?php previous_posts_link('<div class="previous_post_link"></div>') ?>
    							</div>
    							
    						<?php  } ?>
    						
    						</div>
    						<div style="clear:both;"></div>
    						</div>
    					<div style="clear:both;"></div>
    					
    					<?php endif; ?>
    					
    		  </div>
    			</div>
    		</div>
    	</div>
    	
    <?php
    //code to prune posts.
    if (get_option("post_prun") == "yes" && get_option("prun_period") != "" && get_option("post_prun") != "") {
    	$prun_period = get_option("prun_period");
    	$sql = "SELECT `ID` FROM $wpdb->posts WHERE `post_date`<'".date('Y-m-d h:i:s', strtotime("-$prun_period days"))."' AND `post_status`='publish' AND `post_type`='post' LIMIT 10";
    	$sql = mysql_query($sql);
    	while ($row=mysql_fetch_array($sql)){
    		$post_id = (int)$row['ID'];
    
    		if (get_option("prun_status") == "1") {
    			$my_post = array();
    			$my_post['ID'] = $post_id;
    			$my_post['post_status'] = 'draft';
    			wp_update_post( $my_post );
    		} else if (get_option("prun_status") == "2") {
    			wp_delete_post($post_id);
    		}
    	}
    }
    ?>	
    	
    <?php get_footer(); ?>
    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)