Drupal 7 gallery teaser - php

I've created a simple gallery in Drupal using a custom content type. It's really just an article with an image field that can have an unlimited number of items. I've created a custom template for this content type (node--gallery.tpl.php) and for the full page I'm satisfied with the look and feel.
The one thing I'm stuck on is displaying only the first few images in the teaser. I want to display just the first row of images in the teaser (that first 3 images). In the template file, $content['field_images'] contains all the images for the gallery but print render($content['field_images'] outputs all the images (as I would expect).
So, how do I get Drupal to just output the first three items from $content['field_images']? An improvement I would be interested in is how would I get Drupal to output 3 random images although if I know how to cut down the number of images rendered I'm confident I can work that one out myself.

Instead of doing a var_dump or iterating over the array why not install the devel module and make use of its dpm() function which gives a nice output.

In your template, find the appropriate array structure that has the image file names in it. If you can't find it in $content, look at the var_dump output of $node. Write a for loop to iterate over the first three items and for each of these items call either theme_image() or if you have image styles you want to use, theme_image_style(). Pass in the appropriate configuration array to either using the file name you retrieved from the array.

Related

WordPress: Can you add an Excerpt on a PDF

Is it possible to add an Excerpt on a PDF document. Whenever I use the search function on my website I can see the PDFs results, but the text below the link says "No excerpt available". I tried adding text into the Description and Caption fields, but it did not work.
I tried going through the media library > clicking the file > Edit more details then when the file document opens I clicked on the Share Options at the top of the page, but there is no Excerpt option available.
I can see the Excerpt option in Pages and Posts, but not on PDFs.
Is there a way to add Excerpts to PDF documents?
Thank you.
I do not know of any plugins nor native way to do it but I had a similar problem on one of my last projects and here are my solutions.
Either... Creating a child post dedicated to that pdf and copying the content, outputting the child post content onto the parent post.
Or... Simply adding a description to the uploaded media (here the pdf) and outputting the description onto the post.
I went for the second one for dev time restriction, but the first one was also pretty cool because we could add long format additional information linked to the pdf.
Hope that will help!

Get page Body contents in MODX

My MODX site needs to grab the first image from all pages for Open Graph Meta tags, which will be plugged into the Head chunk for all templates.
The problem with this is that not all images are located in the content part of a page. Some are located inside Chunks and others inside TVs. (Finding an image tag from the content is not an issue.)
It might be possible to get all Chunks and TVs and loop through their values to check for images.
But is there a way to get the <body> contents of the resource?
Probably several ways, you can try writing a plugin to parse through the entire content of a page, looks like the OnWebPageComplete event may be the one to use (take a look at the different events to see if one is more appropriate}
You can try and grab the resource from the cache, keeping in mind that any chnks/snippets/TVs called in the page un-cached will not show up in the resource cache file.
You can get a list of TVs once you have loaded a resource & then use getTVValue to get the value.
If you have an image in a chunk, getChunk might work [might, I've never tried to use it that way] to get it's contents but I would image that the image in a chunk would come from a TV ~ so you should be able to retrieve it with getTVValue.
You could also just setup a TV for the OpenGraph image and explicitly set it on a page by page basis.
Probably writing a plugin & some regex is going to be the least painful way of going about it.

Fetch Images from URL - Like Facebook Thumbnail

I am building a "Reddit" like site.
The User can post an URL from which I want to get the correct image with PHP.
What I would need is a script which sites like Facebook or Tumblr use to fetch the Images.
I saw already scripts which get the images by getting the HTML Content and searching for "img" tags.
Are there any better methods/scripts available?
Maybe even scripts which will order the images by the size: The bigger the image the more important it is.
Thanks for answers
You may want to check out PHPQuery, it will allow you easily iterate through all images on a given website. You can then work out the areas of each image and sort them accordingly.
It depends a bit for what you're looking for and what the image is that the user would like to have with his post. To give you an example: I once wrote a method that searches for a logo of a company on the company's website. To do so, I searched for, indeed, the img-tags using simple_html_dom and filtered those tags on the existence of logo in the alt-tag. The results are displayed to the user to select the right image; it could be that you find multiple images fitting your purpose.
I would indeed, as you proposed, have a look at the size and skip small images (e.g. smaller dan lets say 50 px).

cakephp set field in this->data to a related field in database

I am trying to upload multiple images using meioupload which works fine if I set image.1.field and then image.2.field for each field of data. Then loop through and create/save rather than saveall.
My problem comes when I have field which is used as a subfolder for the image within an images folder.
for example I have a form
image.1.product id
image.1.artist
image.1.file to upload
image.2.product id
image.2.artist
image.1.file to upload
now when the items are saved, all data is correct including the belongsto relationship of product id, except the second image is stored in the wrong place.
The first image is stored in images / image.1.artist / file
the second image is stored in images / image.1.artist / image.2.artist / file
This is extremely annoying, and it is simply someting to do with the way the meioupload behaviour sets the subfolder to be a field from the array.
The way I have had to resort to saving the data is by looping through and creating then saving the values, which isnt a problem, but it obviously doesnt work with this method of setting a sub folder.
So a solution could possibly be to simply set the second artist field as blank and only add multiple images for the same artist..
Or to set the data field of artist to the actual field of artist in the related product the image will belong to, but I can't seem to get this to work?
So the question is how can I set the value of this field to the related products artist field that is already in the database for each seperate create/save?
ps. I am sorry if this is a bit long winded.
Right so the problem came because I was sending $this->data as 2 arrays. The solution was to read this->image->product->field('artist') and set it to this->data['Image'][1]['artist'].
This way it sets the field in the first array to artist, which in this particular meioupload behaviour will roll over to the second array of data and hence the image upload (which will then be suffixed with a /) This allows me to upload the images to their corresponding artist directory whilst creating 3 thumbnails and saving the relations, file info and so on.
I found that this doesn't seem to make a difference to loading the images (images work fine even though the display code effectively has two / in it, because the second image will be saved in the database as /dir/artist/ as a pose to the first one which is saved /dir/artist)
IF anyone has an ingenious way to call meioupload one at a time then this would hopefully avoid this slight issue, and then more and more images could be added into the same form..alas I am not clever enough to know how to do this yet..
Any help would be much appreciated!!!!

show uploaded files in gridview using php

i uploaded files into my server image folder.
after upload want to display the uploaded files as thumbnails in the grid view or anything(like windows explorer), also want to select multi files from grid view and download it.. any help to be appreciated.. im using php...
thank you so much...
Here some pointers to get you started:
Loop through the images and simply output them all, then use some CSS padding and width setting to get them into a grid. Alternatively, output them in a table, inserting a </tr><tr> every n loop iterations.
Add a checkbox input using some uniquely identifying value to each image to make it "selectable".
Use some Javascript to spice up the selection process and make it more "Explorer-like".
Try it and come back with more specific questions as you encounter them (after trying to solve them yourself first).
I think you need a PHP Photo Gallery instead. There is an awesome gallery Plogger that you can use.
Otherwise, here are more PHP galleries.
That would be a rather large project to undertake. Try a premade package like:
http://www.gerd-tentler.de/tools/filemanager/ (simple and free)
or
http://www.filerun.com/ (looks good, but requires license)
with the help of <table><tr><td>... you can make a grid view and with using the php code collect all uploaded files into an array then show the file in the grid view by inserting php code in between. In that you can give check boxes and place php code in between to generate an array while user cliks each check box correspondin to that file a link should be passed to the array and then post the values on the download button clik, in the next step you can use the php zip function to ip these file in the array and send it to user as download link

Categories