Attachments Coding Discussion

Started by johny000, September 29, 2009, 12:07:12 AM

Previous topic - Next topic

johny000

hello everyone how are you all
i want ask you some thing about the  Attachments like .jpg, .gif  when you  Attach pic is will show  under the post one after one i like to make it one by one  like 3 or 4 a row

i have made photo in the  photoshop so you know what i'm  talking abot i call it myway.jpg & the one is named smfway.jpg the one one come with smf & the one  named myway.jpg this what i want look like can any one help me ?

SoLoGHoST

#1
The code for displaying attachments is in Display.template.php at Line #405.  This is very possible to do.  I suggest reading up on the fmod php function as this is a good math function to use to determine when to drop the files down to the next row/line.  This function will return the remainder of any 2 given numbers.  So with that in mind you want 3 pictures across according to your pic attached.  Than you should increment a variable by 1 each time the foreach is passed, than check it with fmod:

// placed outside of the foreach loop
$ur_variable = 0;

// placed inside of the foreach loop

$ur_variable++;

if (fmod($ur_variable, 4) == 0)
       // do code for next row
else
      // do code for next pic in the same row



But than you should also take into account that all files may not be picture files also.  So CSS coding for the divs/table elements is important.  Also, probably most important for you to consider when coding this, is how will it look when users click on the image attachments making them bigger inside of the post??  That is, what will happen to the other pics on the same row as that pic??  Or will it just open up a new window instead?

Well Good Luck, is a lot to think about! :)

johny000

ihave added the code to my  Display.template.php but is still did not work so i romve it here is my  Display.template.php can you try it?
iwant 3 row

Quote from: SoLoGHoST on September 29, 2009, 12:45:26 AM
The code for displaying attachments is in Display.template.php at Line #405.  This is very possible to do.  I suggest reading up on the fmod php function as this is a good math function to use to determine when to drop the files down to the next row/line.  This function will return the remainder of any 2 given numbers.  So with that in mind you want 3 pictures across according to your pic attached.  Than you should increment a variable by 1 each time the foreach is passed, than check it with fmod:

// placed outside of the foreach loop
$ur_variable = 0;

// placed inside of the foreach loop

$ur_variable++;

if (fmod($ur_variable, 4) == 0)
       // do code for next row
else
      // do code for next pic in the same row



But than you should also take into account that all files may not be picture files also.  So CSS coding for the divs/table elements is important.  Also, probably most important for you to consider when coding this, is how will it look when users click on the image attachments making them bigger inside of the post??  That is, what will happen to the other pics on the same row as that pic??  Or will it just open up a new window instead?

Well Good Luck, is a lot to think about! :)

SoLoGHoST

You can not just add this code to your Display.template.php file and expect it to work.  There is much work to be done with the code.  I just gave you an example of how to go about doing it yourself.  Thing is, you have to ask yourself a few questions, as the coding of this greatly depends on the answers to those questions.

1. What will happen when I click on 1 of the pictures inside a row of pics?  That is, will it make the picture bigger? as it does normally when clicking pic attachments inside posts, and if so, this will most likely throw off the other pics inside that row.  But if you want to keep it like this, I suppose you could have it resize to 1/3 of the size of the width available in the post and if the pic is any bigger than this than have it open up in a new window.  But now we are getting into the Display.php source file coding.

2. Are you willing to think about this code and try editing the files yourself on a test site, or whatever?  This coding is very much involved, however, the good news on this, is that all of the variables are pretty much defined for you already, you just need to use mostly HTML with a few php echo statements and that should do it.  But the 1 issue that will need to be resolved is the answer to QUESTION #1.

3. How will the attachments look when there is no thumbnail?  That is, when users upload files that are not of an image nature.  How will the link and info be displayed for these attachments?  A thumbnail on the left, a link in the middle, and another thumbnail on the right might look stupid.  Perhaps a pic denoting that it's a FILE instead of an image might be appropriate?  Or maybe you'd want to keep it the way it is?

Ok, so these 3 questions need to be answered before you, or anyone else, does any serious coding!

P.S. -> I don't plan on doing the code for you.  This is an endeavor you can do yourself.  If you require help, ask away, but I'm kinda giving up on doing code for people as this teaches them nothing, and quite frankly I don't have the time for this anymore!  If you want to make a MOD Request, than perhaps this should be in that board, however, if you are wanting SMF Coding help for doing it yourself, fire the questions away and we'll all try to help you out.

Cheers :)

johny000

will i have it set to when some one click on pictures  it open up in a new window  for now & this what i want it to be iwill keep it like this

see all iam trying  to do is save some  space i'm addeding like  over 60 pictures  in one post  the page is to long this why i'm trying to do it the way or maybe you have batter way?


Quote from: SoLoGHoST on September 29, 2009, 11:39:05 AM
You can not just add this code to your Display.template.php file and expect it to work.  There is much work to be done with the code.  I just gave you an example of how to go about doing it yourself.  Thing is, you have to ask yourself a few questions, as the coding of this greatly depends on the answers to those questions.

1. What will happen when I click on 1 of the pictures inside a row of pics?  That is, will it make the picture bigger? as it does normally when clicking pic attachments inside posts, and if so, this will most likely throw off the other pics inside that row.  But if you want to keep it like this, I suppose you could have it resize to 1/3 of the size of the width available in the post and if the pic is any bigger than this than have it open up in a new window.  But now we are getting into the Display.php source file coding.

2. Are you willing to think about this code and try editing the files yourself on a test site, or whatever?  This coding is very much involved, however, the good news on this, is that all of the variables are pretty much defined for you already, you just need to use mostly HTML with a few php echo statements and that should do it.  But the 1 issue that will need to be resolved is the answer to QUESTION #1.

3. How will the attachments look when there is no thumbnail?  That is, when users upload files that are not of an image nature.  How will the link and info be displayed for these attachments?  A thumbnail on the left, a link in the middle, and another thumbnail on the right might look stupid.  Perhaps a pic denoting that it's a FILE instead of an image might be appropriate?  Or maybe you'd want to keep it the way it is?

Ok, so these 3 questions need to be answered before you, or anyone else, does any serious coding!

P.S. -> I don't plan on doing the code for you.  This is an endeavor you can do yourself.  If you require help, ask away, but I'm kinda giving up on doing code for people as this teaches them nothing, and quite frankly I don't have the time for this anymore!  If you want to make a MOD Request, than perhaps this should be in that board, however, if you are wanting SMF Coding help for doing it yourself, fire the questions away and we'll all try to help you out.

Cheers :)

SoLoGHoST

#5
One thing that would make this perfect is that if you had a <DIV> with all images in it, but only displayed 3 image thumbnails at a time.  And only displayed the image attachments.  So all other attachments will just go on another line.  If you look at the way Widgipedia displays their widgets gallery, something like this.  And would even be cool if you can set these into it's own category.  Ofcourse, they do it using the Adobe Flash Player, but this can also be done using only Javascript, and PHP, with some clever CSS Rules and coding.  So, this would solve your image attachments problem and when 1 of the images gets clicked on, according to your attachment settings, will either maximize the pic, if dimensions are less than or equal to available browser space show it, or have it popup a new window.

Well, this is what I recommend if you want to solve your problems.  And personally, will look better IMO.

Cheers :)

EDIT: After I get done coding this MOD I am working on, I will give this a shot and see if I can create a mod that does just what I am talking about in this post.  Maybe call it something like:  Dynamic Image Attachments Display or something along those lines, where the poster will have the option to use it or not when creating/modifying their posts.

Advertisement: