WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: NextGEN Custom Fields] Link in custom field repeating (10 posts)

  1. Calicosun
    Member
    Posted 4 years ago #

    Hi there

    Thank your for the plugin. It is great. I am just having a tiny problem where the information in the custom field is repeating several times in the code - looks fine on the surface but when I check the html code the external link I have put into the custom field has duplicated around four times.

    I have used the plugin to make the title of the main image link to an external website (website portfolio) in NextGEN. I am using the gallery-carousel.php. This is the code I am using:

    <div class="ngg-galleryoverview">
    
    	<div class="pic">
    		<img title="<?php echo $current->alttext ?>"
    	 	alt="<?php echo $current->alttext ?>"
    	 	src="<?php echo $current->url; ?>" />
    
    		</div>
    	</div>
    
    	<div class="albumtitle">
    
    		<a href="<?php echo $current->ngg_custom_fields["Link"]; ?>" > <?php echo $current->alttext ?>
    
    </div>

    I tried using $image->ngg_custom_fields but that didn't work at all. The strange thing is that it is repeating in the thumbnail list and the above code is outside the thumbnail code. Below is the entire code for the page thumbnail. My site is not live yet so I am unable to provide a link:

    <?php
    /**
    Template Page for the gallery carousel
    
    Follow variables are useable :
    
    	$gallery     : Contain all about the gallery
    	$images      : Contain all images, path, title
    	$pagination  : Contain the pagination content
    	$current     : Contain the selected image
    	$prev/$next  : Contain link to the next/previous gallery page
    
     You can check the content when you insert the tag <?php var_dump($variable) ?>
     If you would like to show the timestamp of the image ,you can use <?php echo $exif['created_timestamp'] ?>
    **/
    ?>
    <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?php if (!empty ($gallery)) : ?>
    
    <div class="ngg-galleryoverview">
    
    	<div class="pic">
    		<img title="<?php echo $current->alttext ?>"
    	 	alt="<?php echo $current->alttext ?>"
    	 	src="<?php echo $current->url; ?>" />
    
    		</div>
    	</div>
    
    	<div class="albumtitle">
    
    		<a href="<?php echo $current->ngg_custom_fields["Link"]; ?>" > <?php echo $current->alttext ?>
    
    </div>
    
    	<div class="ngg-galleryoverview">
    	<ul class="ngg-gallery-list">
    
    		<!-- PREV LINK -->
    		<?php if ($prev) : ?>
    		<li class="ngg-prev">
    			<a class="prev" href="<?php echo $prev ?>">◄</a>
    		</li>
    		<?php endif; ?>
    
    		<!-- Thumbnail list -->
    		<?php foreach ( $images as $image ) : ?>
    		<?php if ( $image->hidden ) continue; ?>
    
    		<li id="ngg-image-<?php echo $image->pid ?>" class="ngg-thumbnail-list <?php if ($image->pid == $current->pid) echo 'selected' ?>" >
    
    			<a href="<?php echo $image->pidlink ?>" title="<?php echo $image->description ?>" >
    				<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
    			</a>
    		</li>
    
    	 	<?php endforeach; ?>
    
    	 	<!-- NEXT LINK -->
    		<?php if ($next) : ?>
    		<li class="ngg-next">
    			<a class="next" href="<?php echo $next ?>">►</a>
    		</li>
    
    		<?php endif; ?>
    
    	</ul>
    
    </div>
    
    <?php endif; ?>

    I would really appreciate some help on this - several hours later and I still have no idea why it is happening.

    Thank you.

  2. shauno
    Member
    Posted 4 years ago #

    Hey Calicosun

    I don't know if the $current object runs a hook that is needed for the Custom Fields plugin to get its data.

    Maybe you can try using nggcf_get_field($current->pid, "Link") instead and see what happens.

    So replace your line with:
    <a href="<?php echo nggcf_get_field($current->pid, "Link"); ?>" > <?php echo $current->alttext ?>

    Hope that helps

  3. Calicosun
    Member
    Posted 4 years ago #

  4. shauno
    Member
    Posted 4 years ago #

    Just had a quick look at the full code you posted initially.
    Looks like you don't close the a tag for the custom field link?

  5. Calicosun
    Member
    Posted 4 years ago #

    I get a bit confused when closing a tags in this situation. I have done it like this:

    <a href="<?php echo nggcf_get_field($current->pid, "Link"); ?>" /> <?php echo $current->alttext ?>

    ie. with the />. The code I first posted just had the > .... but that seemed to validate with strict.

    Am I closing it incorrectly? breaks things.

    Thanks for looking at this by the way. I do appreciate it and know it is a pain that my site isn't live.

  6. shauno
    Member
    Posted 4 years ago #

    I don't think that would can close an anchor tag like that.
    Try <a href="<?php echo nggcf_get_field($current->pid, "Link"); ?>"> <?php echo $current->alttext ?></a>

  7. ontwerp73
    Member
    Posted 4 years ago #

    Hi all

    I managed to hack the slideshow for use with: nggcf_get_field
    In imagerotator.php : purpose linkage for every slide picture individually...
    - a get the current pic id
    - define my field : link
    - get the field values via nggcf_get_field function
    - parse it into the xml loop... that;s it!

    Ciao Valentijn

    if (is_array ($thepictures)){
    	foreach ($thepictures as $picture) {
    
    		$picnr = $picture->pid;
    		$fname = "link";
    		$link = nggcf_get_field($picnr, $fname);
    
    		echo "		<track>\n";
    		if (!empty($picture->description))
    		echo "			<title>".strip_tags(stripslashes(html_entity_decode(nggGallery::i18n($picture->description))))."</title>\n";
    		else if (!empty($picture->alttext))
    		echo "			<title>".stripslashes(nggGallery::i18n($picture->alttext))."</title>\n";
    		echo "			<description>".$picture->filename."</description>\n";
    		echo "			<info>".$link."</info>\n";
    		echo "			<location>".$siteurl."/".$picture->path."/".$picture->filename."</location>\n";
    		echo "		</track>\n";
    	}
    }
  8. Calicosun
    Member
    Posted 4 years ago #

    Hi Shauno

    Closing as you suggested breaks the code completely, including removing the title name completely. I work with strict and closing as I did validated fine, plus the code works fine (except for the link duplicating behind the scenes). It is also how the other hrefs are closed in this file and others I have seen when enclosing a php tag so I don't think that is why I am having the duplicated link problem - plus the links display perfectly (with the tag) when view in firebug, html.

    Hi ontwerp73
    Thanks for replying. Hmmm - not sure if your suggestion is going to work for me but thanks... first off I just want the title to have the link. I have the large image displaying on the page with the title underneath and then the thumbnails using the carousel (http://nextgen-gallery.com/templates/carousel/) nextGEN theme. Carousel doesn't use the imagerotator.php file. There will only be some titles that need to link as the portfolio is a combination of both printed work and websites - only want a link for the website.

    Does anyone else have any suggestions as to why this might be happening? Again, apologies for not having the site live - I know this makes things harder to get help.

  9. shauno
    Member
    Posted 4 years ago #

    Hey Calicosun
    I haven't had a chance to look at this in more detail yet, but hopefully I will be able sometime this weekend.
    Let me know if you figure it out before then :)

  10. Calicosun
    Member
    Posted 4 years ago #

    Thanks shauno. I do appreciate you looking into this for me.

    I have spent some more time looking into this but my knowledge of scripts and php is still developing so it is a bit like looking for a needle in a Haystack for me. I have enough knowledge now to have some idea of where to look usually but this one has got me totally stumped.

    I have noticed another problem in that all the titles have become links. I know why that is - I just need to figure out how to code the php so it displays the album title as a link if something is in the custom field and if not just the album title not as a link.

    I am hoping to have my site live by the end of the weekend so perhaps it might be easier if you wait until then - I can post when it has happened - so you can see exactly what I am talking about.

Topic Closed

This topic has been closed to new replies.

About this Topic