- WordPress Plugin Development Beginner's Guide
- Vladimir Prelovac
- 401字
- 2021-05-21 20:12:19
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.
- 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;
- The result of applying this simple CSS code is that Digg Button now shows to the right of the post.
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:

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
- ERP沙盤模擬教程
- Moldflow 2010完全自學(xué)與速查手冊(cè)(模流分析·成本控制)
- Oracle VM Manager 2.1.2
- GlassFish Administration
- Premiere Pro影視后期編輯:短視頻制作實(shí)戰(zhàn)寶典
- 虛擬現(xiàn)實(shí):沉浸于VR夢(mèng)境
- 剪映+Vlog+Premiere短視頻制作從新手到高手
- Building Websites with VB.NET and DotNetNuke 4
- 中文版Photoshop CS5平面設(shè)計(jì)實(shí)用教程(第2版)
- 中文版CINEMA 4D R20 實(shí)用教程
- 好用,Excel數(shù)據(jù)處理高手
- 中文版InDesign CC平面排版設(shè)計(jì)從入門到精通
- AI純美人物繪畫關(guān)鍵詞圖鑒(Midjourney版)
- 48小時(shí)精通SketchUp 8中文版草圖大師建模設(shè)計(jì)技巧
- Photoshop實(shí)例教程:Photoshop 2022(電子活頁(yè)微課版·第3版)