function b4b_number_of_posts($query){
$b4b_options = get_option('b4b_theme_display_options');
$b4b_number_of_posts = $b4b_options['number_of_posts'];
if($b4b_number_of_posts != '' && $query->is_home() && $query->is_main_query()){
$query->set('posts_per_page', $b4b_number_of_posts);
}
}
add_action('pre_get_posts', 'b4b_number_of_posts');
Now I can go back to the share this buttons. First I need to find the hook that I can use for the usage function which I'm looking for in here: http://codex.wordpress.org/Plugin_API/Action_Reference
I thought pre_get_commments would be what I was looking for but upon running the following code it only puts "TESTING" before the recent comments widget:
function b4b_sharing_enabled(){
echo '<h1><b>TESTING</b></h1';
}
add_action('pre_get_comments', 'b4b_sharing_enabled');
After reading through this article, http://wp.tutsplus.com/tutorials/the-beginners-guide-to-wordpress-actions-and-filters/, I've realized I need to look for a filter instead in here: http://codex.wordpress.org/Plugin_API/Filter_Reference
So to add something to the end of your content I've found you only have to do this:
function b4b_sharing_enabled($content){
$content .= '<h1><b>TESTING</b></h1>';
return $content;
}
add_filter('the_content', 'b4b_sharing_enabled');
Leaving you with:
function b4b_sharing_enabled($content){
$content .= '<nav class="sharethis"><ul>';
$content .= '<li><a href="#" onclick="window.open(\'https://www.facebook.com/sharer/sharer.php?u=' . esc_url('http:\/\/'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]) . '\', \'facebook-share-dialog\', \'width=626,height=436\'); return false;">fb</a></li>';
$content .= '<li><a href="#" onclick="window.open(\'https://twitter.com/share?url=' . esc_url('http:\\' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]) . '\', \'facebook-share-dialog\', \'width=626,height=436\'); return false;">tw</a></li>';
$content .= '</ul></nav>';
return $content;
}
add_filter('the_content', 'b4b_sharing_enabled');
The popup for the twitter button works but the problem is the url doesn't show up in the tweet like it should. If I replace $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] with a simple url like google.com it works. Why is this the issue? I guess I'll just have to take a look at it tomorrow. I'm done today.
No comments:
Post a Comment