Hi,
I’m trying to do this http://screencast.com/t/kDbmDCa9
Currently I have a function that looks like this:
/*** Adds ads and share/related items
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (get_post_meta($postid, 'top_ad', true) != 'off' ) {
top_ad code
}
if (get_post_meta($postid, 'bottom_ad', true) != 'off' ) {
bottom_ad code
}
if (is_single()) {
$share_after_ad = do_shortcode('[shareaholic app="share_buttons" id="4703992"]');
$related_after_ad = do_shortcode('[shareaholic app="recommendations" id="4704000"]');
}
$content = $top_ad . $content . $bottom_ad . $share_after_ad . $related_after_ad;
return $content;
}
add_filter('the_content', 'content_injector');
I’m wondering how I can run the theme’s get_review() function and assigned it to a variable $review so I can do something like this:
$content = $top_ad . $content . $review . $bottom_ad . $share_after_ad . $related_after_ad;
return $content;
I don’t really know my way around PHP that well so I’m not sure if I have to use echo get_review() or something like that to make get_review() output its HTML goodies.
So far everything I’ve tried just brings up a white page when I refresh.
hello
try this
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (get_post_meta($postid, 'top_ad', true) != 'off' ) {
//top_ad code
}
if (get_post_meta($postid, 'bottom_ad', true) != 'off' ) {
//bottom_ad code
}
if (is_single()) {
$share_after_ad = do_shortcode('[shareaholic app="share_buttons" id="4703992"]');
$related_after_ad = do_shortcode('[shareaholic app="recommendations" id="4704000"]');
}
$test_module_inst = new td_module_blog();
$review = $test_module_inst->get_review();
$content = $top_ad . $content . $review . $bottom_ad . $share_after_ad . $related_after_ad;
return $content;
}
add_filter('the_content', 'content_injector');
hello,
I have tryd to do something different,
please try this code, if this doesn’t work sorry
function content_injector($content) {
global $wp_query;
global $post;
$postid = $wp_query->post->ID;
if (get_post_meta($postid, 'top_ad', true) != 'off' ) {
//top_ad code
}
if (get_post_meta($postid, 'bottom_ad', true) != 'off' ) {
//bottom_ad code
}
if (is_single()) {
$share_after_ad = do_shortcode('[shareaholic app="share_buttons" id="4703992"]');
$related_after_ad = do_shortcode('[shareaholic app="recommendations" id="4704000"]');
}
$test_module_inst = new td_module_1($post);
$review = $test_module_inst->get_review();
$content = $top_ad . $content . $review . $bottom_ad . $share_after_ad . $related_after_ad;
return $content;
}
add_filter('the_content', 'content_injector');
I have tried that as well Radu and it is not working. To be honest I felt I was doing something wrong this time, because I figured it should work. So I substituted $review with ‘test’ and the word test came up after the content.
I can email you admin access if you want to take a look. I’ve got the code in the theme’s functions.php file. That’s where it should be right? I’m not sure why it’s not hooking up to the new td_module_1 function. Should there be an included PHP file or something at the top of the code?
r1kay, nope it doesn’t create a function. It just assigns an HTML value (with Adsense Javascript) to $top_ad. That’s why top_ad comes before the content. If “top_ad” is set to off in the custom field settings for a post, then nothing gets passed to top_ad, and thus no ad.
You can manually move the get review code in td module 1 to somewhere else on the page. It is located in the footer clearfix of the module 1 file. Thats how i added my own social sharing buttons an fb comments box and moved the get next and prev post to the bottom of the post pages.
Thanks r1kay for that mobile support 🙂
I tried that approach before, but it’s limited to being able to post the review before or after the content.
The way this function is setup now is pretty nice because it takes care of everything without having to edit the theme files (or having to edit them again when the theme gets updated).
I’m sure there’s a way to call the review into a function.
Ocatavian, i tried to copy your code and modify it to my own likes, but i only get a blank page. The code looks a little like this
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (get_post_meta($postid, 'top_ad', true) != 'off' ) {
$top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]')
}
if (get_post_meta($postid, 'bottom_ad', true) != 'off' ) {
$bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]')
}
if (is_single()) {
$share_after_ad = <div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>; do_shortcode('[ssba]');
$comment_after_ad = <div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>; '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
}
$content = $top_ad . $content . $bottom_ad . $share_after_ad . $comment_after_ad;
return $content;
}
add_filter('the_content', 'content_injector');
I edited the code a little more and got it working. However, i know run into the same problem as Octavian. The reviews shows up beneath the sharing buttons and comment box i inserted. Can’t we use the include() function to somehow get the get_review working? My code now looks like this:
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' ))) {
$top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off' ))) {
$bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single()) {
$custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
$facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
}
$content = $top_ad . $content . $bottom_ad . $custom_share . $facebook_comments;
return $content;
}
add_filter('the_content', 'content_injector');
Oh and Octo, u might want to add the if_single code to your ads code like i did to prevent them from showing up on the homepage and other pages!
Yes r1kay it’s basically this:
function revv(){
global $post;
$test_module_inst = new td_module_1($post);
$review = $test_module_inst->get_review();
return $review;
}
function content_injector($content) {
global $wp_query;
global $post;
$postid = $wp_query->post->ID;
if (get_post_meta($postid, 'top_ad', true) != 'off' ) {
//top_ad code
}
if (get_post_meta($postid, 'bottom_ad', true) != 'off' ) {
//bottom_ad code
}
if (is_single()) {
$share_after_ad = do_shortcode('[shareaholic app="share_buttons" id="4703992"]');
$related_after_ad = do_shortcode('[shareaholic app="recommendations" id="4704000"]');
}
$review = revv();
$content = $top_ad . $content . $review . $bottom_ad . $share_after_ad . $related_after_ad;
return $content;
}
add_filter('the_content', 'content_injector');
By using the code above you can move the review to the top of the post, bottom, after content and before ad, etc.
Thanks for helping me out Radu.
Also you will need to comment out or remove the function that calls the review on td_module_1.php
Thanks Ocatavian, did you took my suggestion for adding if single in frond of the ads code? It prevents ads from showing up on catergory pages, the homepage and other pages! It should look like this:
if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' )) {
“Suggestion for adding if single in frond of the ads code? It prevents ads from showing up on category pages, the homepage and other pages”
The advertisement only shows up on the homepage for me and I hide it using CSS.
“Is it possible to add author info and tags to this function? Because all things in the footer like tags, source and author info will show beneath the sharing buttons and comment box.”
No the author info and tags will show above the comment box and under the content.
Well the author info and tags will show up beneath my share buttons and comment box, but i manages to create a new instance for next_prev_post, source_and_via etc.
So it will look like this `function custom_source_via(){
global $post;
$test_module_inst = new td_module_1($post);
$source_via = $test_module_inst->get_source_and_via();
return $source_via;
}
function custom_author(){
global $post;
$test_module_inst = new td_module_1($post);
$author = $test_module_inst->get_author_box();
return $author;
}`
If you look at my code you can see i manually inserted share buttons and a facebook comment box. I’ve added them below the content, but author box and all will automatically show up below the facebook comment box. So i had to manually call the author box and other footer items and manually place them above the facebook comment box and share buttons. I only showed how to create and instance for the footer items so you can manually place them anywhere you want.