• Resolved piratepictures

    (@piratepictures)


    I made a custom attachment view using image.php and put in the next/prev links below the photo. i also added effects to make the links fade on hover and show “previous image” and “next image” text underneath.

    problem is that i used divs to place the text underneath and now on the very first page (and the very last page) i have the “previous image” (and “next image”) text showing but obviously the php prev/next image links are gone. this messes up the page completely…

    what i think i need is a php code for not showing the “previous image” div on the first page but i dont know coding at all. it should be really easy to do i presume…

    it’s a little confusing to explain so please check out the following:

    normal: https://www.missprestin.com/wordpress/?attachment_id=127
    first (or last) attachment pages: https://www.missprestin.com/wordpress/?attachment_id=126

    thanks in advance.

Viewing 13 replies - 1 through 13 (of 13 total)
  • you could probably work with a conditional statement to check if the thumbnail exists, and if not use a default thumbnail in its place.

    could you paste the code of your image.php into a pastebin and post the link to it here?

    Thread Starter piratepictures

    (@piratepictures)

    thanks for getting back.

    here‘s the pastebin link.

    i think what you’re saying would work. and actually, it might make it much easier than what I was thinking which was to remove the ‘previous pic’ text. first, because i’m really not sure how i’d even do that and second because it would mess up the float alignment of my comment box, which it already has…

    the reason seems to be that ‘.previmglink’ does not have any width values set in stytle.css, so if it is empty, it just collapses.

    try to add these settings to style.css:

    .previmglink {width:110px;margin-right:50px;
      height:110px;display:block;}
    .nextimglink {width:110px;margin-right:30px;
      height:110px;display:block;}

    and then edit line 36 in your file:
    <div class="alignright toppadding5"><div class="nextimgtxt">NEXT PIC</div><div class="previmglink"><?php next_image_link() ?></div></div>

    change it to:
    <div class="alignright toppadding5"><div class="nextimgtxt">NEXT PIC</div><div class="nextimglink"><?php next_image_link() ?></div></div>

    hope this works, (if anything, it may need adjustment of the margin values in the extra styles).

    Thread Starter piratepictures

    (@piratepictures)

    perfect, that stops it from collapsing.

    but i still have the problem of the ‘previous image’ text showing up on the first photo page without there being any thumbnail.

    I dont know how to write a conditional statement so that when there is no ‘previous image’ thumbnail to not show the ‘previous image’ text either.

    any ideas?

    the css for that section is here

    i can’t see any conditional statement using wordpress templates and php to do this, using my limited abilities.
    unfortunately, the core function echos the link ( https://phpxref.com/xref/wordpress/wp-includes/media.php.source.html#l709 ) instead of returning it, so it can’t be used easily in a conditional statement.

    in extreme, you could use php ob_start() function:

    change from this code:
    <div class="alignleft toppadding5"><div class="previmgtxt">PREV IOUS PIC</div><div class="previmglink"><?php previous_image_link() ?></div></div>

    to this code:

    <div class="alignleft toppadding5"><div class="previmgtxt">
    <?php ob_start(); previous_image_link(); $link = ob_get_contents(); ob_end_clean(); if($link != '') { echo 'PREV IOUS PIC'; } ; ?></div><div class="previmglink"><?php previous_image_link() ?></div></div>

    totally untested –

    make backup copies before trying

    Thread Starter piratepictures

    (@piratepictures)

    actually, that got it half way there. the text doesnt show up but the black box is still there.

    anyway to put the black box inside that code as well?

    <div class="alignleft toppadding5">
    <?php ob_start(); previous_image_link(); $link = ob_get_contents(); ob_end_clean(); if($link != '') { echo '<div class="previmgtxt">PREV IOUS PIC'</div>; } ; ?><div class="previmglink"><?php previous_image_link() ?></div></div>

    the only concern is that you may get alignment issues if the div with the black background is not there – but give it a try.

    Thread Starter piratepictures

    (@piratepictures)

    yah, i figured i might have trouble with that. i’ll try. maybe i can realign the comments to the right or margin them or something…

    Thread Starter piratepictures

    (@piratepictures)

    Parse error: syntax error, unexpected ‘/’ in /home/content/m/i/s/missprestin/html/wordpress/wp-content/themes/pixel/image.php on line 26

    hmmmm.

    my bad – got the insertion of the closing div wrong – here the corrected version:

    <div class="alignleft toppadding5">
    <?php ob_start(); previous_image_link(); $link = ob_get_contents(); ob_end_clean(); if($link != '') { echo '<div class="previmgtxt">PREV IOUS PIC</div>'; } ; ?><div class="previmglink"><?php previous_image_link() ?></div></div>
    Thread Starter piratepictures

    (@piratepictures)

    that did it. no alignment issues or anything else that i can see. works in chrome, firefox and IE.

    so glad that worked out, thanks a lot.

    well done,
    just leaves the Next Pic link (?)

    you should be able to tackle that yourself ??

    Thread Starter piratepictures

    (@piratepictures)

    yep, i can do that. just totally forgot….

    thanks again!!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘dont show prev/next img links on first/last page’ is closed to new replies.