• Hello,

    On one of my site I am using a very simple theme- so simple that it allows only two widgets on left sidebar. If I want to show ads above the post title then I believe I would need to modify the theme file.

    Anyway, my question is: you say that I should have one text file per category. However, how do I proceed if I want to show, say, 10 ads in same category, in rotation of course!

    Like say, if I wish to show ads in “travel” category then I would need to name the first ad text file as travel.txt. How would I name the subsequent ad files? Should I name them as travel2.txt, travel3.txt, etc., or should I include all the ads belonging to the same category in the same text file?

    Also, once I am done with creating the text file, I would probably add your given php code in my theme file??

    http://wordpress.org/extend/plugins/ad-injection/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author reviewmylife

    (@reviewmylife)

    Hi chinty74, Just to summarise for other readers: you want to show a different advert above the post title, based on the post category. This isn’t supported by the Ad Injection UI, but Ad Injection allows PHP in its ad boxes. I have provided an example of loading ads based on categories, but you now want to extend it to randomly choose from a pool of ads for each category.

    Yes you would need to modify your template to do this – you can use an Ad Injection template ad tag above your post title to do this. Ad Injection will generate an example template ad tag for you (with the correct path) – look in the ‘test ads and template ad examples’ at the bottom of the main UI.

    The problem with one text file for each rotated ad in each category is that your PHP code has to know how many ads there are. Here’s some options:
    1. You could hard code the number of ads for each category into the PHP, but then the code would need updating if you changed the number of ads.
    2. The PHP code could count the number of ads with the name [category][number].txt assuming that all numbers are sequential and start from 1 – this would be more flexible.

    If you did store the ads in individual text files I’s suggest you put a number after *each* ad so travel1.txt, travel2.txt etc. If you called the first one travel.txt with no number then the names would be inconsistent.

    In your PHP code you could then generate a random number between 1 and the number of ads you have, and append this to the name of the ad file which the PHP is loading.

    If you know a bit of PHP this shouldn’t be too hard. If you come up with a solution do share it!

    I might have a go at this myself in the next week. If I come up with a solution I’ll post it here and in the FAQ.

    Plugin Author reviewmylife

    (@reviewmylife)

    Hi chintu74, I’ve extended my code to do what you want. If for example the category nicename is ‘liverpool’ the code will find all the text files in the ad directory with ‘liverpool’ in the file name, and will then randomly select one. It doesn’t matter what naming convention you use for the ad files – as long as the nicename is in there. You can find the example code on advancedhtml – it is the second example.

    Thread Starter chintu74

    (@chintu74)

    Thumbs up! I would check it soon. Thank you 🙂

    One question: does the new feature work on wordpress 2.9.2? This particular blog is of that version (due to another plugin that I have to use here but it is not compatible beyond wp 2.9.2). Let me know.

    Plugin Author reviewmylife

    (@reviewmylife)

    Hi chintu74, I would guess it should work on WordPress 2.9.2, but I have only tested it on 3.2. Do let me know if it works for you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Ad Injection] Text files’ is closed to new replies.