• Resolved oguruma

    (@oguruma)


    I am trying to make a single template, and I want to make a jumbotron/header area that uses the post image as a background.

    What function do I use to pull in the post image URL (falling back to the category image if there are no images uploaded for that post)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello

    there is a function for loading images of GD with a fallback option.

    geodir_get_images($post_id, $options['limit'], $options['show_logo'],$revision_id,$options['types'],$options['fallback_types']);

    https://github.com/AyeCode/geodirectory/blob/master/includes/image-functions.php#L234

    but you also have other options where you can use post_image shortcode.

    example: echo do_shortcode('[gd_post_images title='' types='' fallback_types='cat_default' ajax_load='true' limit='1' limit_show='0' css_class='' type='image' slideshow='true' controlnav='1' animation='slide' show_title='false' show_caption='false' image_size='' aspect='' cover='' link_to='' link_screenshot_to='' bg='' mt='' mr='' mb='' ml='' pt='' pr='' pb='' pl='' border='' rounded='' rounded_size='' shadow='' ]');

    I hope it will be helpful.

    Regards

    Thread Starter oguruma

    (@oguruma)

    Thanks for getting back to me!

    I don’t think that will work, since I need the URL to set a background, and your code will echo an image in tags

    For example:

    <div class="mygeodirectoryarea">
     <h1> The Post Title </h1>
    </div>

    I want to use the post image URL to set a background, for example:
    .mygeodirectoryarea { background-image: url("PUT THE BACKGROUND IMAGE URL HERE")}

    So, I need the image URL, not the image in tags.

    Hello,

    Try this function

    function custom_get_post_image_url( $post_id='' ){
    	$post_id = !empty( $post_id )? $post_id: get_the_ID();
        $featured_img_url = get_the_post_thumbnail_url($post_id, 'full'); 
    	$term_img = '';
    	if ( empty( $featured_img_url ) ) {
            $default_term_id = geodir_get_post_meta( $post_id, 'default_category', true );
            if ( $default_term_id ) {
                $term_img = get_term_meta( $default_term_id, 'ct_cat_default_img', true );
            }
        }
        if ( ! empty( $term_img ) ) {
    		$default_img_id = ( !empty( $term_img['id'] ))? $term_img['id']: 0;
    		$featured_img_url = wp_get_attachment_url( $default_img_id );
    	}
    
    	return $featured_img_url;
    }

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Function to get post image URL?’ is closed to new replies.