Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-05-2011, 03:52 AM   #1
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Wordpress pros inside pls: Random Post w/ thumbnails

Ive been trying to add random post with thumbnail to a blog, but cant get it to work, cant find a plugin :

PHP Code:
<ul>
<?php
$args 
= array( 'numberposts' => 5'orderby' => 'rand''post_status' => 'publish''offset' => 0);
$rand_posts get_posts$args );
foreach( 
$rand_posts as $post ) : ?>
    <li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><p><img src="<?php echo 

get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100">
</p></li>
<?php endforeach; ?>
</ul>
it spits out only the latest post and repeats it 5 times what the hall am i doing wrong???
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

Last edited by tonyparra; 11-05-2011 at 03:54 AM..
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 04:11 AM   #2
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
tried this no luck

Code:
<li><h3>Some Random posts</h3>
 <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>
 </li>
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 05:19 AM   #3
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Quote:
Originally Posted by tonyparra View Post
Ive been trying to add random post with thumbnail to a blog, but cant get it to work, cant find a plugin :

PHP Code:
<ul>
<?php
$args 
= array( 'numberposts' => 5'orderby' => 'rand''post_status' => 'publish''offset' => 0);
$rand_posts get_posts$args );
foreach( 
$rand_posts as $post ) : ?>
    <li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><p><img src="<?php echo 

get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100">
</p></li>
<?php endforeach; ?>
</ul>
it spits out only the latest post and repeats it 5 times what the hall am i doing wrong???
this one displays what i want but the permalink is all the same!! i fucking hate you right now wordpress
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 05:20 AM   #4
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,319
I did something like this recently, but i picked it via category.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 05:36 AM   #5
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Quote:
Originally Posted by fris View Post
I did something like this recently, but i picked it via category.
can you enlighten me please
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 07:26 AM   #6
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Quote:
Originally Posted by tonyparra View Post
this one displays what i want but the permalink is all the same!! i fucking hate you right now wordpress
Im sorry i luv you wordpress
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 07:28 AM   #7
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by tonyparra View Post
Im sorry i luv you wordpress
Wordpress understands we all say things we don't mean when we're angry and it forgives you.
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 07:39 AM   #8
bpluva
Confirmed User
 
Industry Role:
Join Date: Apr 2011
Posts: 235
Quote:
Originally Posted by tonyparra View Post
this one displays what i want but the permalink is all the same!! i fucking hate you right now wordpress
Try the code Below after while have_post the_post

<?php
global $wpdb;
$numposts = 32;
$rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT $numposts");
foreach($rand_posts as $post) :
setup_postdata($post);
?>
<?php endforeach; ?>
bpluva is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 09:17 AM   #9
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Here ya go.. the proper way to do it ><

For use as the main or only loop:
PHP Code:
<?php
$args1 
= array(
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
query_posts($args1);

if (
have_posts()) : while (have_posts()) : the_post(); ?>
    <li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p><img src="<?php echo get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100"></p>
    </li>
<?php endwhile; endif; ?>
Use this as a secondary loop on a page with multiple loops... will save some resources by using the initial query from the main loop as opposed to creating a new query:
PHP Code:
<?php 
$args2 
= array(
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
$rand_posts get_posts($args2);

foreach (
$rand_posts as $post) : setup_postdata($post); ?>
    <li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p><img src="<?php echo get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100"></p>
    </li>
<?php endforeach; ?>
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-05-2011, 08:09 PM   #10
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,319
Quote:
Originally Posted by tonyparra View Post
can you enlighten me please
Had someone that wanted to show recent photos from a category, (each photo represents a post *each image thumb taken from posts with attachments*.

he always had his galleries in 1 category, so he wanted a widget or a shortcode to show recent pics (galleries)
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-06-2011, 12:49 PM   #11
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Quote:
Originally Posted by vdbucks View Post
Here ya go.. the proper way to do it ><
Thanks i did get it to work
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-06-2011, 06:07 PM   #12
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by tonyparra View Post
Thanks i did get it to work
If you want to add a category clause to it.. you could add something like the following to the args array...

via category id:
PHP Code:
$args1 = array(
        
'cat'            => 3,
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
query_posts($args1); 
of course, you could also just use the category name like so:
PHP Code:
$args1 = array(
        
'category_name'        => 'cat_name_here',
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
query_posts($args1); 
or my favorite way, by category slug because I don't like using uppercase letters and/or spaces in my queries:
PHP Code:
$Obj get_category_by_slug('cat_slug_here');
$catid $Obj->term_id;
$args1 = array(
        
'cat'             => $catid,
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
query_posts($args1); 
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.