• Resolved Tunn

    (@iuriem)


    Greg, I added thumbnail support for the “advert” post type:

    /** Enable the thumbnail support for "advert" post type **/
    function add_thumbnail_support_for_adverts() {
       add_theme_support( 'post-thumbnails', array( 'advert' ) );
    }
    add_action( 'after_setup_theme', 'add_thumbnail_support_for_adverts' );

    then added the “advert” post type to the main query (main loop) to display ads together with the default WordPress post type on the home page:

    /** Add "advert" post type to the main query **/
    add_action( 'pre_get_posts', 'add_advert_post_type_to_query' );
    function add_advert_post_type_to_query( $query ) {
      if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'advert' ) );
      return $query;
    }

    but ads still are saved without thumbnails in the database (the _thumbnail_id meta_key). Can you suggest how to solve this? I think that the first uploaded image can be set up as a thumbnail.

    • This topic was modified 7 years, 9 months ago by Tunn.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Tunn

    (@iuriem)

    I rectify. I just want the ads created by WPAdverts to display with thumbnails in/with the main loop on the home page, as are displayed the default WP posts, but my actions, described in the previous message, doesn’t help. Probably, this is a template issue. I must to investigate more, but I will appreciate any help.

    Thread Starter Tunn

    (@iuriem)

    Sorry, but the above add_thumbnail_support_for_adverts() function seems not to work.

    This is a good one (tested):

    add_action('after_setup_theme', 'wptips_custom_init');
    function wptips_custom_init() {
      add_post_type_support( 'advert', array( 'thumbnail', 'post-formats', 'page-attributes', 'comments', 'author' ) );
    }

    Anyway, the question how to display the ad thumbnails with the main loop remains.

    • This reply was modified 7 years, 9 months ago by Tunn.
    Plugin Author Greg Winiarski

    (@gwin)

    Hi, note that that image in the loop will be displayed only if Advert has a featured image set, by default the Ads do not have featured images set, users need to select a featured image in the gallery (for each Ad separately).

    You can automate this by installing Force Featured Image snippet on your site https://github.com/simpliko/wpadverts-snippets/blob/master/force-featured-image/force-featured-image.php

    Also, note that by default Adverts do not support featured images, you can enable support for featured images (thumbnails) using the code below

    
    add_filter("adverts_post_type", "my_adverts_post_type", 10, 2);
    function my_adverts_post_type($args, $type) {
        if($type != "advert") {
            return $args;
        }
    
        $args["supports"][] = "thumbnail";
        return $args;
    }
    
    Thread Starter Tunn

    (@iuriem)

    Greg, thank you!

    Your above code added the support for featured images and using only it I can now add a such image to advert posts from the wp-admin.

    By adding the Force Featured Image snippet from https://github.com/simpliko/wpadverts-snippets/blob/master/force-featured-image/force-featured-image.php an image added to the Gallery can be made “main” (featured), but we will see it also in the Gallery, that is not so good. I think the featured image must have an option to be removed temporary from the Gallery.

    Anyway, I find these functions helpful and I will use them in some cases, but they don’t helped me to display thumbnails with the main loop/query on the home page as regulars posts are. Probably, I must use a custom template for this.

    You can mark this case as solved.

    • This reply was modified 7 years, 8 months ago by Tunn.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WPAdverts thumbnail support’ is closed to new replies.