Simple "No description" if no description exists?

Hey there!

I've been using zenphoto for quite some time now, and I'm very satisfied with it, but there's one thing that would make it even better: a message that prints out "No description" in case a description for an image doesn't exist! I suppose this shouldn't be very difficult to do in the theme itself for those with better knowledge in PHP than me, and that's why I'm humbly asking if someone could help me out. Anyone?

Comments

  • I think if you go into the database, you should be able to set a default description. I haven't taken that close of a look at the database setup for ZP, but I would think it's possible to set a default. I don't know your particular hosting setup, but I would recommend using phpMyAdmin or something similar.
  • trisweb Administrator
    It's better to do this in the theme: `if (getDesc() == "") echo "No Description";` or something like that (I forget the exact syntax).

    It's best to keep it blank in the database; otherwise there's no way to actually know if there actually is a description or not.
  • Jan Member
    Thanks for replying! I did it like this, and it seems to be working pretty good:

    `<?php if (getImageDesc() == null) echo ""; else echo getImageDesc(); ?>`

    Have a nice weekend.
  • trisweb Administrator
    Perfect, that's how I'd do it. Thanks for replying :)
  • To only show the description if it exists:

    `

    <?php<br />
    if (getAlbumDesc() != null) {

    echo '
    ' . getAlbumDesc() . '
    ';

    }

    ?>

    `

    (for image descriptions, swap `getAlbumDesc` for `getImageDesc`)
  • Hi, I know this is a really old topic but I for one have found it very useful - thanks peeps :) However, although the above code works as advised I have found the following little issue:

    When using the following code it shows 'No description added yet!' as it should but I can no longer edit the description using the in-built AJAX functions.

    `<?php if (getImageDesc() == null) echo "No description added yet!"; else echo printImageDesc(true); ?>`

    However, once a description has been added by myself via the main admin section I can still edit it as normal on-the-fly.

    Does anyone know how to make it so that I can still edit the description while viewing the image by clicking on the 'No description added yet!' as per the above code?

    Please help as I really want to show when there is no description but still require the function to be able to edit it using AJAX if thats clear...

    Thanks, CR
  • That is because when you do not call the `printImageDesc(true)` function you do not get the Ajax code.

    A better solution to your problem would be to use phpMyAdmin to insert 'No Description' into any record which currently has an empty description.
  • Hi sbillard, thanks for the advice - although I know how to add the record you speak of, I do not know how to do the initial check and also replace the data when a comment has been added.... Any chance you could help?

    Failing this, how hard would it be to add the 'No description' text to the AJAX code so that when it says 'Click to add a description...' it could be 'No description, click to add on...' but only the 'No description' part of the sentance is shown to the public - the remainder to the admin when they are logged in....

    CR
  • acrylian Administrator, Developer
    Sorry, probably I don't get the issue, but what is unclear about "Click to add a description" meaning there is none? If there is no description there is simple nothing shown for not logged in visitors. Why do they need to get a written "No description" if they see that there is none?
  • The above code works from an end-user point of view - by this I mean that if there is no description then the text 'No description' is shown. However, when I am logged in (as the main Admin) I would have normally have been able to edit my gallery on the fly. However, after the above code changes I can't.

    I would like it so that I can click on the 'No description' text and edit it to actually add one instead of having to go into the main admin section, find the image with no description, then add one frm there.

    So, to recap - when the above code has been added I cannot use the edit on the fly AJAX functions as I could before (unless a comment is already in place, then I can click it to edit as normal).

    I hope you see what I mean...

    CR
  • acrylian Administrator, Developer
    Ah, I see. Try `if (getAlbumDesc() != null) OR zp_loggedin()) {` to the if statement.
  • CR Member
    Hi acrylian, thanks for your fast reply. I have tried what you suggested with: `if (getAlbumDesc() != null) OR zp_loggedin()) {`. However, I am struggling to use the above code within my template, you see I have `<?php if (getImageDesc() == null) echo "No description added yet!"; else echo printImageDesc(true); ?>` at the moment.

    As you can see, my code either allows me to show the comment (if one exists, as well as edit it using AJAX that is tied into the `printImageDesc(true);` command) or show 'No description!' (if there isn't a description for that image). However, it does not allow me to click (and edit) this 'No description' text to add my description using AJAX as it has skipped `printImageDesc(true);` which in turn ties in with the AJAX on-the-fly editing functions...

    To get your code working with what I have already do I use something like this:

    `<?php if (getImageDesc() == null) OR zp_loggedin()) echo "No description added yet!"; else echo printImageDesc(true); ?>`?

    or

    `<?php if (getImageDesc() == null) OR zp_loggedin()) { echo "No description added yet!"; else echo printImageDesc(true); } ?>`?

    I don't understand why checking to see if I (as the Admin) is logged-in using `zp_loggedin()` will allow me to use the AJAX edit-on-the-fly functions of `printImageDesc(true);`.

    Am I missing something....
    Thanks
  • acrylian Administrator, Developer
    If you want to have "No description added yet" shown within the Ajax edit field you will have to hack the ajax functions and replace our standard message.
    Hacking core files is of course not recommend regarding updates.

    Here again my example modified:
    `<?php if (getImageDesc() == null AND zp_loggedin()) echo printImageDesc(true); else echo "No description added yet!"; ?>`

    Not really different from the standard way that can be achieve by just using `printimagedesc(true)`... I still can't follow what the issue with that is.
  • CR Member
    Hi acrylian, thanks again for your help but the code that you have provided does exactly the same as my original code.. Let me attempt to explan what it is I would like to do as we seem to be getting our wires crossed.

    Ok, using `printimagedesc(true)` as per the default settings within any theme will as I am sure you know, display nothing to my visitors if a comment has not been added. However, if one has then it will be shown. The other thing this command does is allow the main Admin to use the edit-as-you-go AJAX functions to simply click the text `Click to add a description...` that is only shown while logged in as said Admin.

    Now, what I wanted to do was rather than show nothing to my visitors when there is no description; I wanted to show the words, 'No description added yet!' - the code I have does this as follows:

    `<?php if (getImageDesc() == null) echo "No description added yet!"; else echo printImageDesc(true); ?>`

    This brings us to the point I am at now where I would also still like to be able to use the edit-as-you-go AJAX functions when the above `No description added yet!` text is being shown but as the code stands at the moment the only time I can use these edit-while-you-browse functions is to edit a comment but not add one.

    Other than giving you access to my gallery or you making the code changes yourself I cannot explain things any clearer than that sorry.

    Anyway, I really hope you can help me.

    Thanks again,

    CR
  • acrylian Administrator, Developer
    Well, I did get you, but isn't showing no text really obvious to your visitors that there is no description....?

    Anyway I gave you the functions to solve that... This should do what you want:

    `
    <?php
    if (getImageDesc() == null) {
    echo "No description added yet!"
    printImageDesc(true);
    } else {
    printImageDesc(true);
    }
    ?>
    `
  • CR Member
    Hi acrylian, the code that you provided didn't work and just gave errors saying the following:
    `Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\*******\Apache2\htdocs\Digital-Photography\themes\Corvus_Corax\image.php on line 107`.

    Although after having a play with what you did provide I now have it working. I ended up using the following code:

    ALBUM.PHP
    `<?php if (getAlbumDesc() == null) echo printAlbumDesc(true) . 'This album does not have a description yet!'; else printAlbumDesc(true); ?>`

    IMAGE.PHP
    `<?php if (getImageDesc() == null) echo printImageDesc(true) . 'This image does not have a description yet!'; else printImageDesc(true); ?>`

    Now when visiting either `album.php`/`image.php` when not logged-in I see 'This album does not have a description yet!' and 'This image does not have a description yet!'. However, if a description is already in place then it is shown as expected :)

    Also when logged-in as the main Admin and visiting either `album.php`/`image.php` I see:

    'Click to add a description...
    This album does not have a description yet!'

    or

    'Click to add a description...
    This image does not have a description yet!'

    Needless to say, all edit-as-you-go AJAX functions now work as they did but with the added descriptive text just how I wanted it :)

    However, one final thing, it would be fab to be able to have it displayed the other way round or even in-line like so:

    'This image does not have a description yet!
    Click to add a description...'

    'This image does not have a description yet! Click to add a description...'

    As before, the 'Click to add a description...' sections are only shown to the main Admin anyway but it would just look cleaner. Any ideas?

    Thank you so far,

    CR
  • CR Member
    Well, anyone have any ideas on this last little alteration?

    "However, one final thing, it would be fab to be able to have it displayed the other way round or even in-line like so:

    'This image does not have a description yet!
    Click to add a description...'

    'This image does not have a description yet! Click to add a description...'

    As before, the 'Click to add a description...' sections are only shown to the main Admin anyway but it would just look cleaner. Any ideas?"

    Thanks,

    CR
  • I'd like my empty description to stay blank and not saying "no description".
    How can I achieve this in the latest version?
    I got rid of these lines in template-functions.php

    if ( $messageIfEmpty === true ) {
    $messageIfEmpty = gettext('(No description...)');
    }

    but this way the description displays (...) unless I change all of them manually.
  • If it is for normal viewers, the nightly builds will have corrected this after tonight's build.

    If you want this for when you are logged in, it would become a problem for the front-end editing capability.
  • Just for the normal viewers is enough. Thanks!
Sign In or Register to comment.