Support

Account

Home Forums Front-end Issues Displaying links or images & images as thumbnails +

Solving

Displaying links or images & images as thumbnails +

  • Hi Elliott

    Much thanks for your previous help.

    Meanwhile I have 2 related questions.

    1) I am using your excellent repeater plugin to create a list of thumbnail images that either
    a) have a link (inserted via ACF field-sets) that goes off to a 3rd party website,
    or
    b) if there is no link inserted via the ACF field-set, then a full size version of the thumbnail image is displayed (using the Lightbox Plus ColorBox plugin)

    My coding skills are not brilliant at pure php, but to do this, I have create the code below (including related field-set data) within a wordpress site. I have marked out the piece of code which is given me trouble (// Start/End of section that doesn’t work) which as you can see is an ‘if’ statement nested inside another ‘if’ statement. Please can you tell me where I have gone wrong?

    2) Also . . . so as to cut down page-load times. Is there a way to make the image within the list <ul id=”pressBadgesList”> load as a thumbnail (i.e. a smaller file) and when clicked on load via the lightbox plugin as a full size version?

    I hope I have been clear in my descriptions and thank you in advance for your help and response.

    All the best

    Phil

    <div class="radioBadges">
    <?php 
    // using normal array
    $rows = get_field('press_badge');
    if($rows)
    {
    	echo '<ul id="pressBadgesList" class="pressBadgesList">';
    	foreach($rows as $row)
    	{
    		echo '<li>' . '<div class=\'radio_badge_title\'><p>' . $row['press_title_printed'] . '</p></div>' ;
    
    // Start of section that doesn't work
    		
    		$links = get_field('press_url');
    		if($links) {
    				echo '<' . 'a ' . 'target=' . '\'_blank\'' . 'href=' . $row['press_url']  . '>' 
    				}
    				else
    				{echo '<' . 'a ' .  'rel=\'lightbox[reviews]\'' . 'href=' . $row['press_image_printed']  . '>' };
    
    // End of section that doesn't work
    
    		echo ('<' . 'img src=' . $row['press_image_printed'] . ' width=\'150\'' . 'height=\'150\'' . '>' .'</a>'.'</li>');
    	}
    	echo '</ul>';
    }
    ?>
    </div>
    

    The created field-set parameters associated with this code are as follows:

    Field Name: press_badge
    Field Type: Repeater

    Repeater Fields
    #1) Field Name: press_title_printed
    #1) Field Type: text
    #1) Formatting: Convert HTML into tags

    #2) Field Name: press_url
    #2) Field Type: text
    #2) Formatting: No Formatting

    #3) Field Name: press_image_printed
    #3) Field Type: Image
    #3) Return Value: Image URL
    #3) Preview Size: Thumbnail
    #3) Library: All

    The webpage in question is here

  • First of all, you didn’t say exactly what is not not working which makes it hard to diagnose.

    Secondly, if you’re using a repeater, shouldn’t you be using get_sub_field instead of get_field?

    Just a couple shots in the dark before Elliot responds.

  • Sorry Arcanepsyche, I tried to be as clear as possible.

    You ask what is not working. Well . . . to answer that, the page just comes up with no content at all – just a blank page! so I guess I’ve made a mistake in the coding somewhere & I believe the problem is in the area marked // Start/End of section that doesn’t work – since if I remove that bit of code the page renders but without the link.

    On the other point – interesting that you say I should be using get_sub_field instead of get_field – however, I have just replaced get_field with get_sub_field in the section of code not working (like you suggested) but it still just creates a blank page (see below for code) – As i said before my php coding is basic to say the least and would appreciate any help you can give. Many thanks Phil

    <div class="radioBadges">
    <?php 
    // using normal array
    $rows = get_field('press_badge');
    if($rows)
    {
    	echo '<ul id="pressBadgesList" class="pressBadgesList">';
    	foreach($rows as $row)
    	{
    		echo '<li>' . '<div class=\'radio_badge_title\'><p>' . $row['press_title_printed'] . '</p></div>' ;
    
    // Start of section that doesn't work
    		
    		$links = get_sub_field('press_url');
    		if($links) {
    				echo '<' . 'a ' . 'target=' . '\'_blank\'' . 'href=' . $row['press_url']  . '>' 
    				}
    				else
    				{echo '<' . 'a ' .  'rel=\'lightbox[reviews]\'' . 'href=' . $row['press_image_printed']  . '>' };
    
    // End of section that doesn't work
    
    		echo ('<' . 'img src=' . $row['press_image_printed'] . ' width=\'150\'' . 'height=\'150\'' . '>' .'</a>'.'</li>');
    	}
    	echo '</ul>';
    }
    ?>
    </div>
    
  • Hi @Phil Futureproof

    You say “blank page”. Do you mean a completely white page? If so, you have a PHP error on the page which is preventing the HTML from being rendered.

    To diagnose this, you will need to turn on DEBUG MODE in your wp-config file and fix the errors reported.

    If this is not the issue, you need to remove all your code and add it in 1 line at a time until you find the line which is not working. This may be the first line of code, but it is smart to debug your code 1 bit at a time as it is easier to solve this way.

    for instance:
    $rows = get_field(‘press_badge’);`
    vae_dump( $rows );
    `

  • Hi Elliot – Thanks for the Debugging info – very useful and I now have a page that is at least rendering in a browser window.

    Still working on this if statement issue – at the moment on the page, all thumbnails open up to the full size image. However, I’m trying to have a situation where, if I’ve entered a url in repeater/subfield 2 then I want it to go to that url rather than load the image. For me, the fact that this doesn’t work implies that the if($links) part of the code (see below) is always taking the else option, so I need to solve what’s wrong with the first part/option, or if it’s not that, the overall structure of the if statement may be at fault. As I said before, this is beyond my current coding knowledge and would appreciate if you could have a look & see if you can see what’s wrong.

    For instance – do I have to include a foreach($links as $link) in this section, similar to the foreach($rows as $row) in the previous bit of code? This might not be the case, but this is where my coding knowledge falls short and any help would be most appreciated.

    To view the page I’m working on in a browser please click here

    Many thanks in advance for your help

    Phil

    
    <?php 
    // using normal array
    $rows = get_field('press_badge');
    
    if($rows)
    {
    	echo '<ul id="pressBadgesList" class="pressBadgesList">';
    	foreach($rows as $row)
    	{
    		echo '<li>' . '<div class=\'radio_badge_title\'><p>' . $row['press_title_printed'] . '</p></div>';
    
    		$links = get_sub_field('press_url');
    		if($links) {
    				echo '<' . 'a ' . 'target=' . '\'_blank\'' . 'href=' . $row['press_url'] . '>' ;
    				}
    				else
    				{echo '<' . 'a ' .  'rel=\'lightbox[reviews]\'' . 'href=' . $row['press_image_printed']  . '>'; }
    
    			
    		echo '<' . 'img src=' . $row['press_image_printed'] . ' width=\'150\'' . 'height=\'150\'' . '>' .'</a>'.'</li>';
    	}
    	echo '</ul>';
    }
    ?>
    
  • Hi @Phil Futureproof

    Sorry, but this forum is a free support service for issues and bugs, not to receive free theme development.

    As a tip, the function get_sub_field will NOT WORK in the context that you have coded. That function only works within a has_sub_field loop, not a foreach loop.

    Please read the docs

    Thanks
    E

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Displaying links or images & images as thumbnails +’ is closed to new replies.