• Resolved hazratnoor

    (@hazratnoor)


    I am using Advanced Ads Plugin on my WordPress website which is working fine and I am getting pixel-perfect behavior of the plugin.

    As per my client requirements, I have to show the attached image (the one that I have added while saving the ad) on a custom template page. For all the saved ads, I have only used Rich Content and Image Ad types only.

    Here is the current code where I want to use the image as well.

    // Query the posts:
    $obituary_query = new WP_Query($args);
    
    // Loop through the obituaries:
    while ($obituary_query->have_posts()) : $obituary_query->the_post();
    	?>
    	<?php 
    		$moreLink = '<a href="' . get_the_permalink() . '"> Read More...</a>';
    		echo '<div class="advert-div" style="padding-bottom: 50px;">'; ?>
    		<h2 class="ad-title"><?php the_title(); ?></h2>
    
    	//Here I want to code for getting the ad image, like this
            //<a href="<?php the_permalink(); ?>" alt="Test Thumbnail">
           // <img src="<?php the_post_thumbnail($post->ID); ?>" />
        	//</a>
    		<?php
    		echo wp_trim_words(do_shortcode("[the_ad id=".$post->ID."]"), 55, $moreLink);
    		echo '</div>';
    		echo '<hr>';
    	endwhile;
    wp_reset_postdata();
    ?>

    I have tried different methods with no luck because I can’t figure out the actual method that is used for getting ad images.

    • This topic was modified 5 years, 10 months ago by hazratnoor.
    • This topic was modified 5 years, 10 months ago by hazratnoor.

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Thomas Maier

    (@webzunft)

    Hi hazratnoor,

    thanks for sharing your use case.

    I am not 100% sure that I understand what you are trying to do. Do you only want to load the image from the ad or the image ad output, so including the link? It looks like it in your comment.

    You could use the PHP function the_ad( AD_ID ); to load the ad output on a specific place.

    If $obituary_query queries your posts then [the_ad id=".$post->ID."] would not load an ad, because there is no ad with the ID of a post. For testing, I would try it with an ad ID you are sure exists.

    I hope this helps.

    Thomas

    Thread Starter hazratnoor

    (@hazratnoor)

    Hi Thomas!

    Thanks for your detailed response. Actually, I can display the ad using the code I have provided in my question. The provided link also shows that the ads are appearing on the page. What I want to do is to show the image of an ad on the right side of each ad as well, just like this

    Thread Starter hazratnoor

    (@hazratnoor)

    The following code is working fine. I just want to add some code (which I cannot figure out in this case) where I have added those comments, saying “Code Goes Here”.

    // Query the posts:
    $obituary_query = new WP_Query($args);
    
    // Loop through the obituaries:
    while ($obituary_query->have_posts()) : $obituary_query->the_post();
    	?>
    	<?php 
    		$moreLink = '<a href="' . get_the_permalink() . '"> Read More...</a>';
    		echo '<div class="advert-div" style="padding-bottom: 50px;">'; ?>
    		<h2 class="ad-title"><?php the_title(); ?></h2>
    
                    //Code Goes Here
                    //Code Goes Here
                    //Code Goes Here
    	
    		<?php
    		echo wp_trim_words(do_shortcode("[the_ad id=".$post->ID."]"), 55, $moreLink);
    		echo '</div>';
    		echo '<hr>';
    	endwhile;
    wp_reset_postdata();
    ?>
    Plugin Author Thomas Maier

    (@webzunft)

    Hi hazratnoor,

    I think I am still missing something.

    > What I want to do is to show the image of an ad on the right side of each ad as well

    What is the difference between the “image or an ad” and the “ad” here? Both would show the image, so you would have it twice.

    When I look at the sample URL then it seems like you want to create a list of all ads. So are you using new WP_Query($args); to query ads and not posts?

    Thanks,
    Thomas

    Thread Starter hazratnoor

    (@hazratnoor)

    I am actually querying posts with post_type = "advanced_ads", like:

    $args = array(
        'post_type' => 'advanced_ads',
        'posts_per_page' => -1
    );
    
    $obituary_query = new WP_Query($args);

    Then why I am unable to get the related image URL (the image which I have added with the ad using Rich Content or Image Ad types using the following code:

    `<a href=”<?php the_permalink(); ?>” alt=”Test Thumbnail”>
    <img src=”<?php the_post_thumbnail(); ?>” />
    </a>`

    Here I get <imag src(unknown)> on inspecting the web page.

    • This reply was modified 5 years, 10 months ago by hazratnoor.
    Plugin Author Thomas Maier

    (@webzunft)

    Thanks. If you have the ad ID then you should query the ad object like this:

    $ad = new Advanced_Ads_Ad( AD_ID );

    and this to get the attachment URL of the image.

    $ad->output['image_id']

    You could also look into advanced-ads/classes/ad_type_image.php => create_image_tag() to see how we are generating the ad code for image ads and find something useful for your case.

    I hope this helps.

    Thomas

    Plugin Author Thomas Maier

    (@webzunft)

    Hi hazratnoor,

    have you been able to find a solution to your coding issue or is there still anything I can help with?

    Best regards,
    Thomas

    Thread Starter hazratnoor

    (@hazratnoor)

    Hi Thomas!

    I have got my solution with the help of your last reply. You may mark this activity as resolved. Thanks for your kind support.

    Regards,
    HazratNoor

    Plugin Author Thomas Maier

    (@webzunft)

    Hi HazratNoor,

    that is great!

    If you have a minute, I would appreciate a positive review of the plugin and support here.

    Thanks,
    Thomas

    Thread Starter hazratnoor

    (@hazratnoor)

    Hi Thomas!

    I have got some problem with advanced ads (showing a single advanced ad). As per my requirements, I have created a template file where I can show all the ads. Now when I click on the ad title (which has an anchor tag holding the actual ad URL – For each ad), I am redirected to the home page, every time. Is there any technical reason for the said issue? Because everything else is working fine and even I have created several other template files for other custom post types and they all work fine.

    Plugin Author Thomas Maier

    (@webzunft)

    Hi HazratNoor,

    could you give an example? What is the target URL, what the page URL, what is displayed when you hover over the ad?

    Thanks,
    Thomas

    Thread Starter hazratnoor

    (@hazratnoor)

    https://rchto.staging.wpengine.com/sponsor-spotlight/

    It shows the exact ad URL when I hover on the ad title. Upon clicking on the ad, the same URL (the exact ad URL) still appear in the browser but after a while, when the page finishes loading, redirection to the home page occurs.

    Plugin Author Thomas Maier

    (@webzunft)

    Thanks, that helped.

    Our ad post type is set up to not have pages created for each ad. Check out the parameters of the custom post type in the get_post_type_params() function in advanced-ads/public/class-advanced-ads.php. You can use the advanced-ads-post-type-params filter to override them.

    The plugin I developed for https://wpadvancedads.com/ad-server-wordpress/ does that and provide a publically available URL for ads. You can just install that or take a look into the code to find the solution.

    I hope it helps.

    Thomas

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Get Specific Ad Image & Display It’ is closed to new replies.