Sunday, July 28, 2013

New plans for coding the options panel - day 10

I've decided that it would be a could idea to keep all (or as much as possible) of the settings usage in the theme-options.php.  Why?  I just like the idea of making it a lot more portable so I can bring it to other themes I work on.  This being said, with the help of the query_posts wp documentation I removed the usage of query_posts from the index.php and used the pre_get_posts hook in the theme-options.php instead:
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:

I've been working on the social buttons for a couple hours now only to get stuck on the damn twitter button.  Here's the current code:
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