In general, this is the case: my site is written in pure HTML more than 1000 pages and of course, if I want to insert advertisements on all pages, then I need to manually insert the ad code on each page, and this, as you understand, is exhausting. Explain how to add ad code to a single file, it appears on all pages. My hosting works with PHP, if that.

Closed due to the fact that the essence of the question is not clear to the participants Visman , xaja , Sergey Mitrofanov , Alex , Aries Oct 23 '15 at 11:07 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    6 answers 6

    At the idea level: add before </body> link to the script that displays the ad unit. Then to change the contents of the block, you will need to edit only one file. Of course, you need to add a link not manually, but run the php script once.

    • In general, it was clear to me that this was the way to do it, but only I could not write a script. people write me for an example. - jo22

    To achieve this effect, you can:

    • Use a template engine (and shove an ad unit into a template)
    • Use Include or require (require_once) on each page.
    • Use SSI
    • Use the .htaccess directive
    • yeah i can't do that (((( - jo22
    • By the way, transfer the site to the database. 1000 pages is tin. - Sergey
    • pages honestly not 1000 and 1800))) - jo22
    • Especially rewrite everything. Write the engine or use ready. - Sergey
    • Yes, and how to transfer to the database, I do not know and I do not see in this sense that I can not understand - jo22

    Making the file adv.js Connecting it to <head> (<script src = "adv.js"> </ script>)

    In adv.js we write something like:

     window.onload = function() { document.getElementById('ad_holder').innerHTML = "тСкст ΠΈΠ»ΠΈ Ρ…Ρ‚ΠΌΠ» ΠΊΠΎΠ΄ Ρ€Π΅ΠΊΠ»Π°ΠΌΡ‹"; } 

    Thus, the ad will be inserted into all tags with id = "ad_holder". The script adv.js needs to be connected to all pages and you only need to edit it.

    • It is not clear what code to place in the pages to display ads. in the page write id = "ad_holder" and everything? - jo22
    • no id = "ad_holder" is displayed simply by the text - jo22
    • First, the insertion will be only in the first element with such an id, secondly, window.onload can be used only once per page, the second call will overwrite the first one, which is not gud. Implementation: <pre> Connect jquery: $ (document) .ready (function () {$ ('. Ad_holder'). Html ('html code');}); And on the page: <div class = "ad_holder"> </ div> <div class = "ad_holder"> </ div> <div class = "ad_holder"> </ div> <div class = "ad_holder"> </ div> </ pre> - Alex Silaev

    In general, there are two solutions: either rewrite the entire site, connecting the admin area and the database (preferably), or add a js script to all pages. On the first decision to write a lot and for a long time, and on the second, everything is simple. Download your website to a folder on a computer, open any file from the root folder using Notepad ++ and replace it in files (including subfolders): </ body> with <script type = "text / javascript" src = "/ js / ads.js "> </ script> </ body>. While there is a replacement, you can go and drink tea (or sleep, as lucky).
    Create an ads.js file in the / js folder - it will display ads. Sample code:

     var b = document.createElement('div'); b.id = 'adblock'; document.getElementsByTagName('body')[0].appendChild(b); b.innerHTML = 'ΠΉΠ° Ρ€Π΅ΠΊΠ»Π°ΠΌΠΊΠΎ'; 

    Well, do not forget to create a twister of advertising and stylize the block on the page.

    • Your answer is also not complete. approximate code is not specific, but I am not a programmer. I do not know how to create a twister, I am not a programmer. Yes, and I do not need a twister. full atas - jo22
    • Then just replace ΠΉΠ° Ρ€Π΅ΠΊΠ»Π°ΠΌΠΊΠΎ for your html-code. In general, this is a sign that it is time to take up web programming. You won't get far on pure html. - ling
    • I did everything but only nonsense is obtained as it is displayed only on the bottom of the site from the left. and I need to be displayed where I want. I inserted into the text and it is still displayed below the site. need another script. - jo22
    • Did you hear about css? - ling

    O_O 1800 pages on pure html .. jo22, I sincerely feel sorry for you = '(

    But if the truth is not lazy, then here’s an option: let the content in the adv.php file with advertising, for example, a banner. And in all the files, insert the contents of this file. prescribe where necessary

     <?php include_once "adv.php"; ?> 

    However, in this case, you will need all 1800 files (even from the thought it becomes so bad: D) to save not as .html, but as .php, but if you feel like spending 3 days instead of 3 minutes on the design, then I think this option is time for you. Then you will simply change the contents of adv.php and the ads will change accordingly on all pages of the site.

    You can write a script that will go through all the files and insert what you need and where you need it.

    • I have all the pages indexed, so I will not redo the extension in php, but unfortunately your code in html does not work. - jo22 pm

    DreamViver has a function (find and replace) in the (edit) section. With the help of this window, you can insert any div block all over the site at once automatically. For example - to find content and replace with content + your div block and select the replace function throughout the site.