• Resolved pare81

    (@pare81)


    Hi Greg,

    I like to ave an standard archive page for ‘advert’ within my child theme. If i create an page like archive-advert.php I can not use this, because if I open the archive I`m redirected to the list.php from wpadverts. Can I get this working somehow? The shortcodes etc I like to use on other pages too. I only Like to have one official theme archive page for ‘advert’ too.

    On my Archive I have an custom loop to ‘advert’ post type.

    I know your template documentation, but the target is to have an archive not on an ‘page’ template.

    Thanks and regards

    • This topic was modified 4 years, 8 months ago by pare81.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    by default WPAdverts redirects from an archive page to the default [adverts_list], if you want to disable this behavior you can add the code below in your theme functions.php file

    
    add_action( "init", function() {
      remove_action('template_redirect', 'adverts_disable_default_archive');
    }, 200 );
    

    Once you add it when a user will access the archives page he should see your archive-advert.php template.

    Thread Starter pare81

    (@pare81)

    Hi Greg,

    Thats do the job to use archive-advert.php but there is one more question to get the archive usable for me.

    If an image is setup (for example through your snippet) as featured the image itself is not visible on archive-advert.php.

    Something is preventing that core WordPress function (get_the_post_thumbnail())doing its job, even though has_post_thumbnail() is true.

    Could you explain me how? I’ve checked this Problem together with Tom Usborne from Generatepress for Generatepress Theme and now we have to ask why this is prevented.

    Thanks Greg, for your support.

    Best Regards
    Patrick

    • This reply was modified 4 years, 8 months ago by pare81.
    Plugin Author Greg Winiarski

    (@gwin)

    Do you have the thumbnails enabled for “advert” custom post type? By default they are disabled.

    You can try getting the post thumbnail with the below code instead

    
    <?php $image_id = adverts_get_main_image_id( get_the_ID() ) ?>
    <?php if($image_id): ?>
      <?php $image = get_post( $image_id ) ?>
      <img src="<?php echo esc_attr( adverts_get_main_image( get_the_ID() ) ) ?>" class="advert-item-grow" title="<?php echo esc_attr($image->post_excerpt) ?>" alt="<?php echo esc_attr($image->post_content) ?>" />
    <?php endif; ?>
    
    Thread Starter pare81

    (@pare81)

    Hi Greg,

    thanks, we getting closer 🙂

    I’ve enabled thumbnails for “advert” post type with the following code, and that works, within the admin, I get now featured images shown.

    add_action('init', 'adosui_thumb_support', 100);
    function adosui_thumb_support()
    {
        add_post_type_support( 'advert', 'thumbnail');
    }

    Also your snippet with adverts_get_main_image delivers an image.

    But what I like to have is the possibility to use the WordPress core function get_the_post__thumbnail() to show the images. I like to build a childtheme and will use how much core functions as possible for my archive page to use the files dynamic and with theme options for archive pages.

    Is there a chance to use get_the_post__thumbnail()?

    Best regards
    Pare

    • This reply was modified 4 years, 8 months ago by pare81.
    Plugin Author Greg Winiarski

    (@gwin)

    If you have the ‘thumbnail’ support enabled for the “advert” custom post type with your custom code then you should be able to use the get_the_post_thumbnail() function assuming some featured image for an Advert is selected.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom theme Archive for Advert’ is closed to new replies.