More details in descriptions
-
Hi,
Thanks for this plugin !
After some research I am able to better control its use. While a graphical interface directly on the edit page content (TinyEditor) will be a big plus!For my part I try desperately to customize the display of my files.
– Document Gallery is very good for miniature but not great for details.
– EG Attachment is very good for the details but not great for thumbnails.Is it possible to get the same rendering (information visible in the screenshot) with DG ??
Screenshot : https://www.casimages.com/i/150729122028449931.jpg.html
Thanks (sorry for this bad transaltion)…
Julien
-
Hi Julien,
What you want is definitely possible. You will want to take a look at the
dg_icon_template
PHP filter documented on the Installation tab. It allows for you to customize the output of individual icons and exposes a number of markup fields which are replaced with dynamic content by DG.The fields currently available are:
%link%: The URL that will be loaded when the user clicks the icon.
%target%: The target attribute for the anchor tag (e.g.: _blank, _self).
%img%: The URL pointing the the image that will be displayed.
%title%: The human-readable title of the attachment.
%title_attribute%: The escaped title (above), safe for using HTML tag attributes.
%description%: The attachment description (only present when rendering descriptions).
%extension%: The document file extension.
%size%: The human-readable file size formatted by size_format.
%path%: The system path pointing to the document.If I have some time later I’ll try to put together an example of how to replicate the output you are looking for, but the functionality is definitely available.
-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! ??
Hello Dan,
Thank you for your quick reply.
You reassure me!
But the PHP it’s not my field. Can you refer me a little?I found this:
class-document.php/*========================================================================== * OUTPUT HTML STRING *=========================================================================*/ /** * Returns HTML representing this Document. * @filter dg_icon_template Filters the DG icon HTML. Passes a single * bool value indicating whether the gallery is using descriptions or not. * @return string */ public function __toString() { include_once DG_PATH . 'inc/class-thumber.php'; $thumb = $this->gallery->useFancyThumbs() ? DG_Thumber::getThumbnail( $this->ID ) : DG_Thumber::getDefaultThumbnail( $this->ID ); $target = $this->gallery->openLinkInNewWindow() ? '_blank' : '_self'; $repl = array( $this->link, $thumb, $this->title_attribute, $this->title, $target, $this->extension, $this->size, $this->path ); $find = array( '%link%', '%img%', '%title_attribute%', '%title%', '%target%', '%extension%', '%size%', '%path%' ); $description = ''; // if descriptions then add filterable tag and value to replaced tag if ( $this->gallery->useDescriptions() ) { $repl[] = $this->description; $find[] = '%description%'; $description = ' <p>%description%</p>'; } $doc_icon = ' <div class="document-icon">' . PHP_EOL . ' <a href="%link%" target="%target%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%" /><br>%title%</a>' . PHP_EOL . ' </div>' . PHP_EOL . $description; // allow developers to filter icon output $doc_icon = apply_filters( 'dg_icon_template', $doc_icon, $this->gallery->useDescriptions(), $this->ID ); return str_replace( $find, $repl, $doc_icon ); }
I must not be very far ^^
Test :
$doc_icon = ' <dl class="attachments attachments-large"><dt class="icon">' . PHP_EOL . ' <a title="%title%" href="%path%" %target%>' . PHP_EOL . ' <a href="%link%" target="%target%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%" /></a>' . PHP_EOL . ' </a>' . PHP_EOL . ' </dt>' . PHP_EOL . ' <dd class="caption">' . PHP_EOL . ' <strong>Titre</strong> : <a title="%title%" href="%path%" %target%>%title%</a>' . PHP_EOL . ' <br/>' . PHP_EOL . ' <strong>Légende</strong> : %CAPTION%' . PHP_EOL . ' <br/>' . PHP_EOL . ' <strong>Nom du fichier</strong> : %FILENAME%' . PHP_EOL . ' <br/>' . PHP_EOL . ' <strong>Taille</strong> : %size%' . PHP_EOL . ' </dd>' . PHP_EOL . ' </dl>' . PHP_EOL . $description;
https://www.casimages.com/i/150730072057363502.jpg.html
Not very good, so, i’m not a developper ^^
Hi Julien,
You have found where the logic exists for this functionality, but you definitely do not want to modify the plugin directly. That’s why we’ve build filters in ??
Basically, a filter allows you to change the plugin output without changing the plugin itself. In this case, I believe you’ll want something like below:
add_filter('dg_icon_template', 'dg_icon_details_mod', 10, 3); function dg_icon_details_mod($icon, $descriptions, $id) { if ($descriptions) { $icon = '<div id="document-gallery-1" class="document-icon-wrapper descriptions">' . ' <div class="document-icon">' . ' <a href="%link%" target="%target%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%"></a>' . ' </div>' . ' <strong>Titre:</strong> %title%<br>' . ' <strong>Legende:</strong> %description%<br>' . ' <strong>Nom du fichier:</strong> ' . basename( get_attached_file( $id ) ) . '<br>' . ' <strong>Taille:</strong> %size%</p>' . '</div>'; } return $icon; }
Now, where this code goes is a bit more tricky. If you have a custom theme where you aren’t likely to get updates, you can put this into a “functions.php” file in the root of your theme’s directory. The more likely case is that you are using a theme from somewhere else. If that’s the case, you won’t want to modify that theme’s functions file because then changes will be lost whenever you get an update. What you’ll want to do instead is create a child theme. This process is documented here, and is very easy to setup ??
If you have any questions, please feel free to ask!
-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! ??
Hello Dan,
Ok I followed all the steps but your code does not work.
The plugin is healthy. The child theme works. The small code snippet is KOhttps://www.julien-moreau.fr/hautlespieds/wordpress/index.php/2015/07/29/304/
– My functions.php
<?php // Chargement en attente des CSS // https://codex.www.ads-software.com/fr:Th%C3%A8mes_Enfant add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } // Plugin Document Gallery (thumbnails) add_filter('dg_icon_template', 'dg_icon_details_mod', 10, 3); function dg_icon_details_mod($icon, $descriptions, $id) { if ($descriptions) { $icon = '<div id="document-gallery-1" class="document-icon-wrapper descriptions">' . ' <div class="document-icon">' . ' <a href="%link%" target="%target%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%"></a>' . ' </div>' . ' <strong>Titre:</strong> %title%<br>' . ' <strong>Legende:</strong> %description%<br>' . ' <strong>Nom du fichier:</strong> ' . basename( get_attached_file( $id ) ) . '<br>' . ' <strong>Taille:</strong> %size%</p>' . '</div>'; } return $icon; } ?>
Hi Julien,
The way I wrote the filter, you’ll only get the extended output if descriptions is enabled, so you’ll want to include
descriptions=true
in your shortcode. Also be sure that you have your child theme set as your active theme.-Dan
Yeah !!
https://www.casimages.com/i/150731084647651366.jpg.html
It’s a shame to not have the GUI to add the options.
Because I see that too: https://www.ads-software.com/support/topic/not-working-1102?replies=10#post-6718291
Very interesting ??Thank you very much Dan !!
Fantastic! Glad you got it working! ??
Yeah, I think a UI for configuring the icon template is a good idea — I was actually thinking that as I was falling asleep. I’ll add that to the issue tracker and hopefully we’ll get that in in the not-too-distant future.
-Dan
- The topic ‘More details in descriptions’ is closed to new replies.