SmashinGeeks | Geeks In Action

Posted by Orange Game 2011-04-08

SmashinGeeks | Geeks In Action

Link to SmashinGeeks

Display Blogroll and Friends Links in WordPress in Two Columns

Posted: 07 Apr 2011 11:34 AM PDT

After a long time ago, we are going to release a simple and easy code to display your friends and Partners links in two columns. Its a very simple PHP code and can be used in theme itself or as a shortcode. The links should be there in Blogroll links which you can edit from your Dashboard.

Just note that this piece of code is not a new one, it is derived from the “Display Categories in Two Columns” code from BlogohBlog.

There are two basic methods of displaying it, whether using shortcodes or creating your own widget.

Creating Two Columns Blogroll Widget

Its the best way to display two columned Blogroll links in any of the sidebar of your blog. Just what you have to do is place the below code in your theme’s functions.php file.

//Partners & Friends function br() { register_sidebar_widget('Friends & Partners', 'my_text_widget5'); } function my_text_widget5() { ?> <h4>Friends & Partners</h4> <?php $cats = explode("<br />",wp_get_links('title_li=&echo=0&depth=1&style=none')); $cat_n = count($cats) - 1; for ($i=0;$i< $cat_n;$i++): if ($i<$cat_n/2): $cat_left = $cat_left.'<li>'.$cats[$i].''; elseif ($i>=$cat_n/2): $cat_right = $cat_right.'<li>'.$cats[$i].'</li>' ; endif; endfor; ?> <ul> <?php echo $cat_left;?> </ul> <ul> <?php echo $cat_right;?> </ul> <?php } add_action('widgets_init', 'br');

You can edit the bolded section according to your need.

Display Using Shortcodes

You can use shortcodes in your Wp editor too, its also a portable way of displaying Blogroll links in two columns.

function br() {
<h4>Friends & Partners</h4> <?php $cats = explode("<br />",wp_get_links('title_li=&echo=0&depth=1&style=none')); $cat_n = count($cats) - 1; for ($i=0;$i< $cat_n;$i++): if ($i<$cat_n/2): $cat_left = $cat_left.'<li>'.$cats[$i].''; elseif ($i>=$cat_n/2): $cat_right = $cat_right.'<li>'.$cats[$i].'</li>' ; endif; endfor; ?> <ul> <?php echo $cat_left;?> </ul> <ul> <?php echo $cat_right;?> </ul> <?php } add_shortcode('tclinks', 'br'); 

The CSS

To display Blogroll in two columns, the basic CSS you need is place this code in your Theme’s stylesheet file.

.fleft {  border-right: 1px solid lightgrey;  float: left;  font-weight: bold;  width: 125px; } .fleft li a {  color: black; } .fright {  float: left;  font-weight: bold;  padding-left: 25px;  width: 123px; } .fright li a {  color: black; }

0 komentar:

Posting Komentar

Search

Twitter updates