• Hi

    So this tells the featured image link whether it should open in ‘Full Post’ or just a lightbox ‘image’.

    // Meta Box
    	function cudazi_thumb_linksto(){
    	  global $post;
    	  $custom = get_post_custom($post->ID);
    	  $featured_image_link_to = $custom["featured_image_link_to"][0];
    	  $featured_image_link_to_url = $custom["featured_image_link_to_url"][0];
    	  ?>
    	  <p><?php _e('Choose on a post by post basis where the featured image thumbnails to link to.','cudazi'); ?></p>
    	  <p>
    	  <select name="featured_image_link_to">
    	  	<option value=''><?php _e('Default','cudazi'); ?></option>
    	  	<?php
    	  		$featured_image_link_to_options = array(
    	  			'post' => __('Full Post','cudazi'),
    	  			'image' => __('Image','cudazi')
    	  		);
    			foreach ( $featured_image_link_to_options as $k => $v ) {
    				if ( $k == $featured_image_link_to ) { $sel = " selected='selected'"; }else{ $sel = ""; }
    			  	echo "<option " . $sel . " value='". $k ."'>" . $v . "</option>";
    			}
    	  	?>
    		</select>
    		<em><?php _e('or','cudazi'); ?></em> <?php _e('Custom URL:','cudazi'); ?> <input type="text" style='width:300px; border-style:solid; border-width:1px;' name="featured_image_link_to_url" value="<?php echo $featured_image_link_to_url; ?>" /> <?php _e('(Full URL - Video, External Page, etc...)','cudazi'); ?></p>
    	  <?php
    	}

    Since I have no deep understanding of PHP, I have no idea how to comepletely turn the link off. I’d like to add an [Coming soon] option (along ‘post’ and ‘image’) so the image would be unclickable (without any ‘a href’). Maybe I could cheat and hide it with CSS, but I don’t even know how to add a class to that image/meta box/function.

    Any ideas?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter khanate

    (@khanate)

    So, this actually says what to do with the link

    if ( $featured_image_link_to == 'post' ) {
    					$featured_image_link = get_permalink();

    What should I write instead of get_permalink, to disable the link?
    Or maybe, how do I add a CSS class in there (to hide it or something)

    Pretty please help me out

    Hi,
    you can simply comment out the specific row.
    try:

    if ( $featured_image_link_to == 'post' ) {
    					//$featured_image_link = get_permalink();

    see if that make it.
    Also having a link to your site will help us give you more help with css and html.
    Regards

    Thread Starter khanate

    (@khanate)

    Thanks for the reply, but no, that didn’t removed the link, it links to the home/index page now…

    here’s the web https://www.zemaraim.com/page/2/ (the bottom row has the ‘post’ setting.)

    [No bumping, thank you.]

    Hi, you should have a loop.php file check that file for <div class="post-thumbnail">. The code right after that should generate the “a href” if you can share it … would be grate.

    Thread Starter khanate

    (@khanate)

    Oh, sorry for the bump, didn’t realise its that much of a no-no.

    So that div is located in my functions.php, the a href is at the very end

    // Get Featured Image + Link
    	function cudazi_get_featured_image( $img_size, $fallback ) {
    		global $post;		
    
    		$cudazi_post_hide_featured_single = get_post_meta($post->ID, 'cudazi_post_hide_featured_single', true);
    		if ( is_single() && $cudazi_post_hide_featured_single ) {
    			return false;
    		}
    
    		if ( has_post_thumbnail() ) {
    			$featured_image_link_to = get_post_meta($post->ID, 'featured_image_link_to', true);
    			$featured_image_link_to_url = get_post_meta($post->ID, 'featured_image_link_to_url', true);
    			if ( $featured_image_link_to_url ) {
    				$featured_image_link = $featured_image_link_to_url;
    			}else{
    				if ( $featured_image_link_to == 'post' ) {
    					$featured_image_link = get_permalink();
    				}else if ( $featured_image_link_to == 'image' || !$featured_image_link_to ) {
    					$featured_image_link = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    					$featured_image_link = $featured_image_link[0];
    				}
    			} // end if url set
    			$featured_image = get_the_post_thumbnail($post->ID, $img_size, array( 'class' => '' ));
    		}else{ // no thumbnail set
    			$featured_image_link = get_permalink();
    			$featured_image = $fallback;
    		} // end if has featured image				
    
    		if ( has_post_thumbnail() ) {
    			return "<div class='post-thumbnail'><a href='" . $featured_image_link . "'>" . $featured_image . "</a></div>";
    		}
    	}

    Deleted the a href from there, and the image lost the link, which is nice, but how will I determine/assign which images will have it and which won’t, now that is going to be quite a task.

    Btw, here’s the theme I’m using.

    Help me understand: you want to disable all links from photos/images or you want to do this only for featured images?
    What is the criteria that make the difference between a photo/image that has link and one that hasn’t?

    Thread Starter khanate

    (@khanate)

    Well the idea is simple; I’ve got a grid of portfolio items/thumbnail images and at the backend I can determine if they’re gonna open in full post (permalink) or if they just open in a lightbox image; (the backend is carried in the meta-boxes.php)

    I’d like to add another option for ‘in progress’ works, where the thumbnail won’t be clickable at all, so it would just show an alt text, like ‘Coming soon…’.

    basically what I need to do is add another line like this:

    $featured_image_link_to_options = array(
    	  			'post' => __('Full Post','cudazi'),
    	  			'image' => __('Image','cudazi')
    	  			'coming-soon' => __('Coming Soon','cudazi')

    and somehow tell that ‘coming-soon’ won’t have any a href (the get permalink is obviously not good)

    else if ( $featured_image_link_to == 'coming-soon' ) {
    					$featured_image_link = get_permalink();
    				}

    but I don’t know how to assign it with another has_post_thumbnail like this:

    if ( has_post_thumbnail() ) {
    			return "<div class='post-thumbnail'>" . $featured_image . "</div>";
    		}

    (man, this support forum needs a better way of showing code, needs some color differentiation, or at least the iframe should be scalable!)

    You can create a custom post meta for each “coming soon” post and use it as checker:
    let’s say you add a post meta to each “coming soon” post like this
    post_sts = “csoon” (you can set is as you wish);
    then in your code you have:

    if ( has_post_thumbnail() ) {
                          $is_coming_soon = get_post_meta($post->ID, "post_sts", true);
                          if ($is_coming_soon=="csoon") {
                              return "<div class='post-thumbnail'>. $featured_image . "</div>";
                          } else {
    			return "<div class='post-thumbnail'><a href='" . $featured_image_link . "'>" . $featured_image . "</a></div>";}
    		}
    	}

    you can set up the custom post meta from the dashboard in the edit page of each post. Hope this will do it.
    Regards

    Thread Starter khanate

    (@khanate)

    Hm, I get error on the third line of your code; in EditPad, the { brackets on first and third line of your code are displayed in red (which means they’re “un-inclosed, or something)

    Thread Starter khanate

    (@khanate)

    thing is, for my portfolio post types, I can’t turn on Custom Fields [from the Screen Options]. Downed the Custom Field Template, but its making my head spin, can’t make out how to turn it on.

    Thread Starter khanate

    (@khanate)

    Could you please elaborate how to create a custom post meta?

    Is it done thru Custom fields? Where should I put [what?] code?

    I looked up a few tutorials, but things get a little complicated for me, espcially when I don’t have custom fields in my portfolio post type…

    Yes if you set a custom field you can get the value of that custom field using the “get_post_meta()” function.
    The code had an extra “}” at the end so this should do it:

    if ( has_post_thumbnail() ) {
                          $is_coming_soon = get_post_meta($post->ID, "post_sts", true);
                          if ($is_coming_soon=="csoon") {
                              return "<div class='post-thumbnail'>. $featured_image . "</div>";
                          } else {
    			return "<div class='post-thumbnail'><a href='" . $featured_image_link . "'>" . $featured_image . "</a></div>";
    		}
    	}

    you can use custom fields with any theme and any plugin the only thing is if you have a visual custom field option or if you need to code it using php or directly in mysql.

    Thread Starter khanate

    (@khanate)

    Yeah, already tried removing some of the “}”, but still get errors on the third line.

    The first “{” seems to be wrong, as its highlighted in red..

    Or maybe its because I didn’t set the “coming soon” meta, yet?

    (Which I have no idea how to do, tbh)

    Thread Starter khanate

    (@khanate)

    Man, this is making my head spin… Please help me out.

    HOW do I set the the custom field?

    Ughhh this is too complicated to just simply turn off a link!

    There are more ways to set up a custom field, it seems that the easy ways are not for you (since you are using custom post types and a lot of custom plugins) so you have 2 options use a template to add custom fields from the front-end, develop your own plugin to set them up from the backend (a lot of work with the first 2), use a php -widget visible only if you are logged in as admin and set up custom fields from the front end(this will work only if you have sidebars/footer where you can include the widget)
    it will look something like this:

    <?php if( current_user_can( 'edit_users' ) ) {
    if ($_POST['custom_value']){
    $add_meta = $_POST['custom_value'];
    add_post_meta($post->ID,"custom_key",$add_meta);
    echo "Meta added!";
    } else echo "<form name='ad_meta' action='' method='post'><label>Meta:</label><input type='text' name='custom_value'><input type='submit' name='add_it' value='submt'></form>";
    } ?>

    so this will not work out of the box, you will have to make sure that there is a variable “$post->ID” that returns the current post id, you will have this option only in the singe post page, but it’s a starting point, you can obviously customize it even more to suit your needs by adding an input for the meta_key value (if you don’t want it to be predefined in the php code) and so on.
    Regards

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘How to disable Featured Image Link’ is closed to new replies.