Viewing 1 replies (of 1 total)
  • I just did that!
    After struggling a while, I came up with a somewhat easy solution. Just added the code below at includes/fields/featured_image.php. But then this is no good if f I’m to update the plugin in the future, so I guess there might be a better place to add the code, like in your theme, or in the theme-customisations-master plugin, but I don’t really know how to make sure it’s loaded on time…
    The code just duplicates the featured image field code, but replacing wp_get_attachment_image with wp_get_attachment_image_src:

    add_filter( 'qw_fields', 'qw_field_featured_image_url' );
    /*
     * Add field to qw_fields
     */
    function qw_field_featured_image_url( $fields ) {
    
    	$fields['featured_image_url'] = array(
    		'title'            => 'Featured Image URL',
    		'description'      => 'The "post_thumbnail" URL of a given row.',
    		'output_callback'  => 'qw_theme_featured_image_url',
    		'output_arguments' => TRUE,
    		'form_callback'    => 'qw_field_featured_image_url_form',
    	);
    
    	return $fields;
    }
    /*
     * Image attachment URL settings Form
     */
    function qw_field_featured_image_url_form( $field ) {
    	//$image_styles = _qw_get_image_styles();
    	$image_styles = get_intermediate_image_sizes();
    	?>
    	<p>
    		<label class="qw-label">Image Display Style:</label>
    		<select class='qw-js-title'
    		        name='<?php print $field['form_prefix']; ?>[image_display_style]'>
    			<?php
    			foreach ( $image_styles as $key => $style ) {
    				$style_selected = ( $field['values']['image_display_style'] == $style ) ? 'selected="selected"' : '';
    				?>
    				<option
    					value="<?php print $style; ?>" <?php print $style_selected; ?>><?php print $style; ?></option>
    			<?php
    			}
    			?>
    		</select>
    	</p>
    <?php
    }
    
    /*
     * Return the images URL
     *
     * @param $post
     * @param $field
     */
    function qw_theme_featured_image_url( $post, $field ) {
    	$style = $field['image_display_style'];
    	if ( has_post_thumbnail( $post->ID ) ) {
    		$image_id = get_post_thumbnail_id( $post->ID, $style );
    		return wp_get_attachment_image_src( $image_id, $style )[0];
    	}
    }
    
    
Viewing 1 replies (of 1 total)
  • The topic ‘Image/Attachment URL’ is closed to new replies.