Tagged: inject content
After reading through the following post :
Which goes over how to have content/ad appear after every x number of activities in the feed.
I’ve been trying to manipulate the code to only show the content/ad after n activity.ie. the content only shows up once after the x post not infinite times after every x number of posts.
Does anyone know the code for this?
This is the current code that makes content appear infinite times every n posts. How would i change this to make the content only come up once at a specified number of posts?? thanks
‘/**
* Inject content into BuddyPress Activity stream after ‘n’ activities.
*/
function buddydev_inject_content_after_n_activities() {
static $current_activity_index = 1;// change $n to the correct number of activities.
$n = 5; // After how many activities you want to inject content.if ( $current_activity_index % $n === 0 ) {
?>
<li class=’activity-item activity-ad-item activity-custom-entry’>
Your code snippet …<?php
// show the activity injected content.
}
// increment the current index.
$current_activity_index ++;}
add_action( ‘bp_after_activity_entry’, ‘buddydev_inject_content_after_n_activities’ );’
Hi Daniel,
Thank you for the question.The above code will not be able to help you achieve it.
To make sure that the content appears only 1 time, you need to keep track if the content was shown on the current page.
To do that you will need to add js code and track the view state by using cookie/local or session storage.
are you comfortable writing js code? If yes, I will be glad to provide you the steps for achieving it.
Thank you
BrajeshHi Dan,
Thank you for the reply.I am sorry, I am unable to assist you with this due to lack of time. I do believe it is worth investigating and providing a solution in future.
Regards
BrajeshHi Brajesh, I would be curious to know how to do this via js.
I am trying to inject a widget area that shows up once after the 1st activity feed item only.
Hi Adam,
Thank you for the question.The solution is to assign an id to each of the injected content to uniquely identify them. Then, set cookies to keep these ids for a small amount for time(say 1 hour).
On the server side, you can check the cookie and avoid showing the old content.
Hope that helps.
Regards
Brajesh
You must be logged in to reply to this topic.