Welcome
We've been working hard

A link is automatically added to the picture in the dream CMS document content, and a new window opens

Everyone who uses Dream CMS knows that sometimes we want to open a new window automatically after clicking a picture. How can we do this? below CMS Tutorial Network Two points of the summary are shared with you.

1、 Method 1: Use jquery

 <script type="text/javascript"> $(function() { $('.show-article img').each(function(i){ if (! this.parentNode.href) { $(this).wrap("<a href='"+this.src+"' target='_blank'></a>"); } }); }); </script>

be careful:
1. The premise is that your current page has a jquery library
2. Change the class or ID in the external div of your document content to your own

2、 Method is implemented with PHP

Open the/include/extend.func.php file
Add at the bottom

 /** *Document Content Picture Auto Add a Link New Window Open Picture * * @access    public *@ param string $body content * @return    string */ function setBodyimg($body) { $matches = array(); preg_match_all('/<img[^>]*src\s*=\s*([\'"]?)([^\'">]*)\1(.*?)>/isu', $body, $matches); $img_array = $matches[0]; $src_array = $matches[2]; foreach ($img_array as $key => $value) { $body = str_replace($value, "<a href='{$src_array[$key]}' target='_blank'>".$value."</a>", $body); } return $body; }

Then the tag of the calling content in the content template

 {dede:field.body/}

Revised as:

 {dede:field.body function="setBodyimg(@me)"/}

 

Like( zero ) Reward
Do not reprint without permission: New Start Blog » A link is automatically added to the picture in the dream CMS document content, and a new window opens


Follow the public account "New Start Software Steward"

Get the latest network resources and cracking software!
Play with all kinds of software

comment Grab the sofa

You must log in before commenting!

 

Reward the author of the article if you think it is useful

Thank you very much for your reward, we will continue to give more high-quality content, let's create a better online world together!

Scan Alipay and reward

Scan WeChat and reward