• Resolved robertboyl

    (@robertboyl)


    Quick question, is there a way to automatically put the description of a photo to be the FILE NAME? Or perhaps, if theres no description, show the file name or date in which photo was taken?

    Thanks!!

Viewing 10 replies - 16 through 25 (of 25 total)
  • Benjamin

    (@benjaminowens)

    Hi @robertboyl, I didn’t notice the notification email on this thread, my apologies!

    To use a nicer format change the F j, Y to d/m/y — how DateTime->format() works is documented here on php.net — just scroll down to the the format table.

    What does the code you are using look like now? Images’ description is stored in the description attribute, and the title is in alttext — the following will force the title and description for all new images:

    add_action('ngg_added_new_image', function($image) {
        $mapper = C_Image_Mapper::get_instance();
        $image->description = 'DESCRIPTION';
        $image->alttext = 'TITLE';
        $mapper->save($image);
    });
    Thread Starter robertboyl

    (@robertboyl)

    Thanks a lot, Benjamin.

    Strange, with your new code, it put the image name in the title, not the date. Can you sent the entire file?

    The previous code, which you had sent, below.

    add_action('ngg_added_new_image', function($image) {
        if (empty($image->description))
        {
            $mapper = C_Image_Mapper::get_instance();
            $date = new \DateTime($image->imagedate);
            $image->description = $date->format('F j, Y');
            $mapper->save($image);
        }
    });

    I wanted to put the date in the description field, so that it shows up in the gallery.

    Thanks.

    Benjamin

    (@benjaminowens)

    What exactly does the code you have right now look like?

    The snippet you last pasted will only set the description to the date if the description is empty; to make it always apply you’ll need to remove the if() and its braces ({}) like so:

    add_action('ngg_added_new_image', function($image) {
        $mapper = C_Image_Mapper::get_instance();
        $date = new \DateTime($image->imagedate);
        $image->description = $date->format('F j, Y');
        $mapper->save($image);
    });
    Thread Starter robertboyl

    (@robertboyl)

    Hi, Ben

    It didn’t work. I used this code you posted now.

    * Description: Custom modifications for example.org
     * Version: 0.1
     * Plugin URI: https://example.org/
     * Author: Your Name Here
     * Author URI: https://example.org/
     */
    
    add_action('ngg_added_new_image', function($image) {
        $mapper = C_Image_Mapper::get_instance();
        $date = new \DateTime($image->imagedate);
        $image->description = $date->format('F j, Y');
        $mapper->save($image);
    });

    It’s leaving the title with the filename and the description blank.

    The original code you posted was working better, adding the date to the description. I wanted the date in the title.

    Original code is here: https://www.ads-software.com/support/topic/description-of-photo-filename/

    Thanks.

    Benjamin

    (@benjaminowens)

    Hi @robertboyl

    To move the date to the tile you just need to assign it to the image’s alttext attribute, like so:

    add_action('ngg_added_new_image', function($image) {
        $mapper = C_Image_Mapper::get_instance();
        $date = new \DateTime($image->imagedate);
        $image->alttext = $date->format('F j, Y'); // Image title
        $image->description = 'Image description'; // Remove this line to use metadata from the image file
        $mapper->save($image);
    });
    Thread Starter robertboyl

    (@robertboyl)

    Thanks a lot, Ben. I put that code, it didn’t work out. It put the image’s filename in the title and description is blank.
    Any chance we can talk via Whats app or Skype?
    I can give u access.
    Thanks!

    Thread Starter robertboyl

    (@robertboyl)

    Dear Ben,
    How are you? When you can, please reply?
    Thanks

    Benjamin

    (@benjaminowens)

    I’m good, thanks; just keeping busy ??

    That sounds like the code isn’t running at all; do you still have the header comments at the top of the file? They are necessary to make WordPress detect a PHP file as a plugin.

    <?php
    /*
     * Plugin Name: example.org Site Tweaks
     * Description: Custom modifications for example.org
     * Version: 0.1
     * Plugin URI: https://example.org/
     * Author: Your Name Here
     * Author URI: https://example.org/
     */
    
    add_action('ngg_added_new_image', function($image) {
        $mapper = C_Image_Mapper::get_instance();
        $date = new \DateTime($image->imagedate);
        $image->alttext = $date->format('F j, Y'); // Image title
        $image->description = 'Image description'; // Remove this line to use metadata from the image file
        $mapper->save($image);
    });
    Thread Starter robertboyl

    (@robertboyl)

    Hi, Ben

    Thanks. Put that exact code, still won’t work. Just adds image’s filename name to the title.

    Any chance you can remote access my machine sometime?

    Can I send you a private message with my personal data? How?

    Thanks!!

    Benjamin

    (@benjaminowens)

    I’m sorry @robertboyl I don’t believe I’m allowed to do that here.

    I think however that I can suggest filing another report at https://www.imagely.com/report-bug/ and in the issue description note that this a question for me.

    I’m going to mark this as closed again.

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Description of photo = filename’ is closed to new replies.