Author Topic: How to make Separate Random Gender's Photos widgets  (Read 1856 times)

Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1006
  • Karma: +56/-7
How to make Separate Random Gender's Photos widgets
« on: June 25, 2013, 02:47:43 AM »
I manipulated the random members widget to show two different sets of gender photos. In this case, my example was Random Females and Random Males.
The idea was to add these separated photo sets in the photos.html page. I tested this out in my offline development environment with success.

Why not just simply make a div layer in the html file with the headings of Random Females and Random Males? Well, after testing this out on a smart phone, the formatting went way off with the text separating from the rest of the photos. I wanted the titles to stick with the photos where it should be.

So, here's what I did.
1. In plugins/widget/members/members.class.php, I added this code between line number 73 and 75. Notice the text 'rand2'

Code: [Select]
case 'rand2':
$query="SELECT a.`fk_user_id`,UNIX_TIMESTAMP(a.`last_changed`) as `last_changed` FROM `{$dbtable_prefix}user_profiles` a WHERE a.`_photo`!='' AND a.`status`=".STAT_APPROVED." AND a.`del`=0";
if (isset($this->config['cmp_field']) && isset($this->config['cmp_to']) && !preg_match('/[^a-z0-9_]/',$this->config['cmp_field'])) {
if (!isset($this->config['cmp']) || !in_array($this->config['cmp'],array('=','>','<','>=','<=','like'))) {
$this->config['cmp']='=';
}
$this->config['cmp_to']=sanitize_and_format($this->config['cmp_to'],TYPE_STRING,$GLOBALS['__field2format'][FIELD_TEXTFIELD]);
$query.=" AND `".$this->config['cmp_field']."`".$this->config['cmp']."'".$this->config['cmp_to']."'";
}
$query.=" ORDER BY RAND(".mt_rand(0,1000).")";
break;

2. In the same file, I added this code between lines 145 and 147. Notice both 'rand2' and the language string key 'rndi_str3'
Code: [Select]
case 'rand2':
$widget['title']=$GLOBALS['_lang']['rndi_str3'];
$widget['id']='widg_rand_members';
break;

3. Next I went into the admin control panel > Site Setup > Skin Settings > Skin Translate.
At the bottom, I added a new key.
Key name: rndi_str3
Description: title: Random Member
Save to file: plugins/widget/members/members.class.php
Clicked Save

4. In the empty input line next to the new string, I wrote in the text: Random Male
clicked Save and then Regenerated the skin.

5. my code in the photos.html file now looks like this (notice 'rand2' and 'cmp_to'=>'1' to represent the Random Males):
Code: [Select]
<!--widget="members(array('mode'=>'rand','cmp_field'=>'f1','cmp_to'=>'2','total'=>5))"-->

<!--widget="members(array('mode'=>'rand2','cmp_field'=>'f1','cmp_to'=>'1','total'=>5))"-->

Now, I don't know if it's possible to point the "More Members" link towards the individual genders or not. If someone can come up with that, then please share.
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

Tooken

  • Prime Member
  • ****
  • Posts: 146
  • Karma: +3/-0
Re: How to make Separate Random Gender's Photos widgets
« Reply #1 on: June 25, 2013, 10:04:17 AM »
This is a very useful post Marble and i will try this when i get home (at work now) regarding what you say, my concerns are how to make a whole widget that could have 5 diff. genres and being those 5 the ones with the most voted photos. Something you already replied to on my last post. I think the widget customization is well worth to explore.

Thanks for sharing this, applause to you
David

Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1006
  • Karma: +56/-7
Re: How to make Separate Random Gender's Photos widgets
« Reply #2 on: June 25, 2013, 04:23:20 PM »
Thanks! I'm glad you can find this useful as well.  :) Certainly, if you had a real estate or a car reselling website, this random members widget technique can be applied to that as well. So, if someone had different categories for luxury cars, sports cars, trucks, golf carts etc. then they could find this useful. Although in their case, they might want to remove the More Members link by turning off the display of that item (.link_more) in the css file and then replacing it with some other link, otherwise customers might be confused because it will take them to all the vehicles on the site.

I forgot to mention that in the language strings page, look for the string named: rndi_str1 with the description: title: Random Members. In there, change the String input text to Random Females (or anything else you want).
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

Tooken

  • Prime Member
  • ****
  • Posts: 146
  • Karma: +3/-0
Re: How to make Separate Random Gender's Photos widgets
« Reply #3 on: June 25, 2013, 08:36:08 PM »
Well I will be honest my site will be more of a social network to specific types of people though all involved on the same community not really the classic dating site, hence why i need the 5 genres .. its not going to be a male/female thing..