官术网_书友最值得收藏!

Styling the output

Our Digg button looks like it could use a better positioning, as the default one spoils the look of the theme. So, we will use CSS to reposition the button.

Cascading Style Sheets or CSS for short (http://www.w3.org/Style/CSS/) are a simple but powerful tool that allows web developers to add different styles to web presentations. They allow full control over the layout, size and colour of elements on a given page.

Time for Action – Use CSS to position the button

Using CSS styles, we will move the button to the right of the post.

  1. We will accomplish this by first encapsulating the button in a <div> element. Then we will add a CSS style to this element stating that the button should appear on the right, with a left margin towards the text of 10 pixels.
        // create a Digg button and return it    
        $button="
        <script type='text/javascript'>
        digg_url = '$link';
        digg_title = '$title';
        digg_bodytext = '$text';
        </script>
        <script src='http://digg.com/tools/diggthis.js' type='text/javascript'></script>";
    
     // encapsulate the button in a div
     $button='
     <div style="float: right; margin-left: 10px; margin-bottom: 4px;"> 
     '.$button.'
     </div>';
            
        return $button;    
  2. The result of applying this simple CSS code is that Digg Button now shows to the right of the post.
    Time for Action – Use CSS to position the button

What just happened?

We used CSS to move the button to a desired position. CSS is extremely useful for these kinds of tasks and is commonly used in WordPress development to enhance the user experience.

// encapsulate the button in a div
$button='
    <div style="float: right; margin-left: 10px; margin-bottom: 4px;">    
'.$button.'
</div>';

We have basically encapsulated our button in a <div> element and forced it to the right edge by using float: right CSS command inside a style tag.

We could further experiment with the placement of the button until we find the most satisfying solution.

For example, if we hook to the_title filter instead of the_content, and moved the button to the left, we would get the following result:

What just happened?

Certainly, having good CSS skills is a very valuable asset in WordPress plugin development.

Have a go Hero

Now that our button is finished, there are a lot of possible customizations you can make to the look or position of your button, using both built-in Digg options and CSS.

  • You can use the digg_bgcolor, digg_skin, digg_window parameters of Digg JavaScript to control the appearance of the button (refer to http://digg.com/tools/integrate)
  • Use CSS to play with the layout of the button
  • Create similar plugins that will allow the user to submit content to sites such as Stumble Upon or Reddit
主站蜘蛛池模板: 石台县| 西丰县| 广丰县| 阿拉尔市| 施甸县| 兰溪市| 龙门县| 乌什县| 南汇区| 金寨县| 盐边县| 庆阳市| 论坛| 昆山市| 商城县| 三门县| 南澳县| 湖南省| 满洲里市| 突泉县| 台中县| 岳池县| 巫溪县| 洛宁县| 南丰县| 苏尼特左旗| 广饶县| 花莲县| 南昌县| 清河县| 五指山市| 潼南县| 凤翔县| 永善县| 大宁县| 梅州市| 理塘县| 夏津县| 延川县| 汽车| 新化县|