• I’m currently working with this wordpress theme and just created this function that adds my ads, share buttons and comment box to my post pages. However, i have some review posts on my site (you know, a rating system with stars or percentages) and this theme inserts this review box below the content of the post. So the review box will apear below the comment box and share buttons that i inserted with this function. I tried to insert the review box code in my function. Here’s my function.php code:

    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()) {
        $review = //WHAT CODE DO I ADD HERE?
        $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 . $review . $bottom_ad . $custom_share . $facebook_comments;
    return $content;
    }
    add_filter('the_content', 'content_injector');

    The post pages are constructed with this code located in a file called td_module_1.php (i left out the upper part of the file because it’s not relevant):

    } else {
                $buffy .= $this->get_content();
            }
    
            $buffy .= '<footer class="clearfix">';
                $buffy .= $this->get_post_pagination();
                $buffy .= $this->get_review();
                $buffy .= $this->get_the_tags();
                $buffy .= $this->get_source_and_via();
                $buffy .= $this->get_social_sharing();
                $buffy .= $this->get_author_box();
                $buffy .= $this->get_next_prev_posts();
            $buffy .= '</footer>';
    
        $buffy .= '</article> <!-- /.post -->';
    
        $buffy .= $this->related_posts();
    
        return $buffy;
    }
    }

    As you can see the line $buffy .= $this->get_review(); inserts the review box. The question here is, what code do i need to add after $review = to have the function insert the review box? I already tried things like $review = $td_module_1->get_review();

    It should be possible to get that get_review function to work in my functions.php, right?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You need the actual class name, not the file name, unless the two are the same. Whatever it is, use it with the scope resolution operator, a double colon ::. Let’s say it is the same as the file name. It may not work, but you can try td_module_1::get_review();. Success depends on the nature of the function.

    What will work, if you can find the proper object reference, is $object->get_review(); You might deduce the object reference from context. Or you might see something like $object = new td_module_1().

    Failing that you could try assigning your own new object using the same line you were looking for above. All the defaults will be applied, which may be fine, but if it needs specific mandatory arguments, a blind new object will fail.

    Chances are one of those will work. If not, you’ll need to determine how to properly construct a new object with the correct parameters.

    Thread Starter r1kay

    (@r1kay)

    Thanks for your reply bcworkz!

    I’ve tried the scope resolution operator but it will result in a blank page.

    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()) {
    		$review = td_module_1::get_review();
    		$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 . $review . $bottom_ad . $custom_share . $facebook_comments;
    	return $content;
    	}
    add_filter('the_content', 'content_injector');

    So this did not work, or did i do something wrong. I couldnt find an object reference in the code…

    Moderator bcworkz

    (@bcworkz)

    There could be a few things causing the error. To see the error message define WP_DEBUG as true in wp-config.php. Or check the PHP error log.

    Can you confirm the class name from source code? The first word on the line will be class, the next word is the actual class name.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with constructing the single post lay-out through funtions.php’ is closed to new replies.