0

I am using the advanced_ads plugin on my WordPress website which allows me to create different types of ads including image ad, rich content ad etc. The plugin allows shortcodes usage for showing ads on my website.

I am using the rich content ad type on a custom template file which allows me to show all the ads just like blog posts. Now I want to limit down the number of content for each ad to 30-50 words, so I can only show a short description of the ad and user will then view the whole ad in a single page upon clicking on the Read More button.

So far, I am willing to use the_excerpt(); but advanced_ads allows [the_ad id] shortcode to place an ad in the content. In my code, I loop through all those ads and assign the id's of each ad to the shortcode like [the_ad id=".$post->ID."] and it works fine.

However, I am willing to integrate the_excerpt(); in my code for limiting down the number of words along with showing a button like Read More that will allow users to view the full content.

Here is my code:

<?php echo '<div class="advert-div">'; ?>
<h2 class="ad-title"><?php the_title(); ?></h2>
<?php
echo do_shortcode("[the_ad id=".$post->ID."]");
echo '</div>';
0

use wp_trim_words() like so:

<?php 
$moreLink = '<a href="' . get_the_permalink() . '">Read More</a>';
echo '<div class="advert-div">'; ?>
    <h2 class="ad-title"><?php the_title(); ?></h2>
<?php
echo wp_trim_words(do_shortcode("[the_ad id=".$post->ID."]"), 55, $moreLink);
echo '</div>';

Just substitute however you need to get the permalink for your add in to the $moreLink if needed.

  • The wp_trim_words works for me. – teccraft Mar 5 '19 at 16:59
  • When I am hovering on the Read More button of any ad, it shows that particular link but when I click on it, I am redirected back to my home page. What is wrong here with the permalink? – teccraft Mar 6 '19 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.