I just want to know if there is a way of inserting content (such as an ad, or a particular node) in between views lists. In my case, i'm trying to set up a grid view with some ad content in between. Right now i'm using a very roundabout way by making 3-4 views that have the same parameters, only that their content has an offset in order to continue the flow. For example:
(View of content type X that displays nodes 1-6) | (Ad) | (Copy of previous view that displays nodes 7-12) | (Ad) |
(Another copy of the view that displays nodes 13-20)...
As you can see, this method creates too many database queries. I imagine Views isn't the way to proceed with this particular task, but I'm willing to learn to create my own View-like query if someone points me in the right direction. Thanks in advance!
Comments
One approach that would work
One approach that would work with a single view.
Set up the as you want, though having a style of unformatted works best for this.
Under basic setting, next to theme click 'information'.
We want the one called 'Style output', click on 'Style output' and you will see the default template. Copy what you see in the textbox and paste into an editor. Click 'Back to theming information.' and look next to 'Style output' to see list of template file names you can use to override the default template. I generally pick the one like views-view-unformatted--node-your-view-name.tpl.php where your-view-name will reflect the name of your view. Now save the contents of your editor to a file by the chosen name, this file should be in your theme directory. Now back in views click 'Rescan template files', the file you just saved should be in bold.
You can now modify the save template file. In you case I would use $id to print ads every N nodes.
Hi. Thanks for your quick
Hi. Thanks for your quick response! Although I've been searching for the past half hour for some of the things you are mentioning, I am not able to find a basic setting with the theme's style output, etc... I am currently running drupal 5 with views 1, so i'm assuming these are features of views 2.
However, your train of thought lead me to think that there might be something I can do in the template.php code for that particular view that would insert an ad every N nodes. I've attached my current code below, which has taken me some time to put together from different snippets and forum issues (i wanted a grid view that includes a theme file for each entry/set of fields). I am rather new to PHP so right now i'm clueless as to how I am able to embed the ad. I guess i might be able to play around with the $count variable to trigger an action (insert ad) every certain amount of iterations, but i don't know what this action would look like. I appreciate your help!
Hi viz8, did you managed to
Hi viz8, did you managed to display the ad in between your grid view?
I'm looking for the same solution as well... *bump*
Yes, actually. Sorry i didn't
Yes, actually. Sorry i didn't post my solution. Here's what i wrote on my template.php (there might be a better solution, but this one works fine at the moment). Let me know if you have any questions.
P.S. This code also assigns a phptemplate to each node.
Thank you
Thank you for your code.
I modified your code for Views' list_view.
But I wanted to show the ad once.
here is what I have in template.php.
Can you elaborate on using $id for this?
I very much need something like this as I am building a site for a sports writer who is supported by advertising, and I use Views 2 heavily on the site.
I can set up the template as you suggested and have it override correctly, however I am new to PHP and don't have the slightest idea how to proceed beyond that point. Can you give me a little more info on how to use $id for this purpose, or possibly point me to a tutorial or code snippet that would be similar?
I did try to muck around with the two templates the other posters provided, though I could not adapt them to my own needs (and I'd rather stick with unformatted instead of list or grid views). I'll keep trying to figure it out, but any helpful hints or advice would be greatly appreciated.
Got a simple method...
I posted a question about this under Views as well, and got a response on a quick and easy way here.
This does what I need in a pinch, though it does require actually specifying each $id number that should have an ad (i.e. the 5th, the 10th, etc.).
I hope to learn more about PHP so that I can figure out how to produce a simple script that can count every fifth node automatically, up to an indefinite amount. So many things to learn, so little time!
Your link go on a user page
Your link go on a user page :/
https://interface-network.com - Interface Network is an action and research technology governance agency.
use jQuery?
Is there a downside to inject the ad with jQuery? I have to do this for a project and was wondering what people thought. It's a blog with maybe 6-8 teasers on a page, with one ad in the middle of the posts.
Andrew Mellenger
https://mellenger.com
https://move2.help
One you html must be
One you html must be structure enough for this to be practical, two if the user has javascript disabled your ads will not show.
How I can do in the same way
How I can do in the same way as you had before ? I mean : (View of content type X that displays nodes 1-6) | (Ad) | (Copy of previous view that displays nodes 7-12)
Thanks
I did it this way before.
When I set it up this way, I had created a view to show the first five entries of a blog, and then used the footer of the view to insert the ad code. I set this to be displayed as a block.
I cloned that view and then under the 'Basic Settings' of the new view I changed the options under 'Items to Display'. The second field in this area is 'offset', which you can use to skip a certain number of results.
So, since my first view returned 5 articles, for the second view I gave it an offset of 5 so that it would start with the 6th blog entry and on. Since I used these views as blocks, I just stacked them one over the other in one of the regions of the site to give the impression of one continuous view with an ad in the middle.
I think performance is not
I think performance is not good with this system...
https://interface-network.com - Interface Network is an action and research technology governance agency.
Here is step by step tutorial
Here is step by step tutorial on how to insert your custom code after n-th row (for exaple adsense code after first and sixth row): http://www.jasom.net/how-to-add-custom-code-adsense-after-first-row-in-d...
Basically you need to override defaul views-view-unformatted.tpl.php with this code: