Articles Comments

digitalpercept.com » Entries tagged with "WordPress"

Using CSS and PHP to style the Wordpress Tag Cloud Widget

styling_wordpress_tag_cloud_widget

Tag Cloud – Defination – What is a tag cloud?

A tag cloud is a stylized way of visually representing occurrences of words used to described tags. The most popular words are normally highlighted in a larger, bolder font. Visitors to a blog or site using a tag cloud, are able to easily see the most popular topics within the website by clicking on the respective tags.

If you are using the Wordpress Tag Cloud widget, you will come to know that you are unable to style it the way you like. If you call it directly from PHP in your template there are a few options you can use to control the look. The widgetized version does not give you access to options to control the style
neither you can style it with CSS. Not a problem! Now, You can fix the Tag Cloud Widget with this php function without touching the Wordpress core code.

HTML code of the default Tag Cloud widget:

< a href="http://www.digitalpercept.com/?tag=wordpress" class='tag-link-1' title='3 topic' style='font-size: 8pt;'>wordpress< /a>

The CLASS attribute is unique per tag and does not include any weighting information. And the STYLE tag hard-codes the font size based on weight but would override any CSS font-sizing we might have been able apply with the CLASS. Lets use the font-size information from the STYLE to determine the weight and
write a small filter function to rewrite the CLASS and STYLE declarations so we can use CSS to style the tag cloud.

Copy this filter function code block to your functions.php file in your active template.


// filter tag clould output so that it can be styled by CSS
function style_my_tag_cloud($tags)
{
$tags = preg_replace_callback("|(class='tag-link-[0-9]+)('.*?)(style='font-size: )([0-9]+)(pt;')|",
create_function(
'$match',
'$low=1; $high=5; $sz=($match[4]-8.0)/(22-8)*($high-$low)+$low; return "{$match[1]} tagsize-{$sz}{$match[2]}";'
),
$tags);
return $tags;
}

Hook the created php function into the rendering of the tag cloud widget

add_action('wp_tag_cloud', 'style_my_tag_cloud');

The function rewrites the tag links to look like this:

< a href="http://www.digitalpercept.com/?tag=wordpress" class='tag-link-1 tagsize-1' title='3 topic'>wordpress< /a>

The default tag cloud uses font-sizes from 8 to 22 points. The filter function uses a regular expression to extract that size and remap the default range (8-16) to the range defined by the $low and $high variables, for this example I used 1 though 5. An additional CLASS is added ‘tagsize-n’ where ‘n’ is 1-5 and then the STYLE attribute is removed. With the additional class you can now add something like this to your style.css and make the Tag Cloud look any way you’d like!


a.tagsize-1 { font-size: 8px; }
a.tagsize-2 { font-size: 10px; }
a.tagsize-3 { font-size: 12px; }
a.tagsize-4 { font-size: 14px; }
a.tagsize-5 { font-size: 16px; }

Filed under: OpenSource, Web Design, Web Dev, WordPress

Installing WordPress On Windows Using XAMPP

xampp_wordpress_windows

After reading this article, you will be able to install WordPress on your Windows system.

Installing Wordpress on the local system helps out testing different themes, plugins without going live. If you try such changes in live, Wordpress is prone to crash.

Another benefit is, you can test run the posts locally and then make them live to make sure about the correctness. If you are a developer then you can develop plugins for wordpress by playing around with WordPress code.

Step1 :

Installing XAMPP (A package of Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin )

XAMPP is a way to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin.

You can download XAMPP Lite hereat apachefriends.org.

After downloading and double-clicking on this file it will display a screen that asks you what folder you want to extract XAMPP to. Extract it to the root of C:\ drive on your PC. You can certainly extract it to the root of your secondary hard drive as well.

One suggestion: Uncheck the option to install apache and MySQL as windows services.

If you double-click on the shortcut icon of XAMPP, It will open a window in the lower-right hand corner of your screen that will allow you to start the Apache web server software and the MySql database software.

xampp_start
xampp_run
XAMPP Control Panel with Apache and MySql running.

Start your web browser, Browse to http://localhost/xampp.

xampp_browser_localhost
Step2:

Installing database for WordPress

You should see a setup page that will guide you through setting up the database for your WordPress install.

xampp_browser_phpmyadmin_li

  1. Select your language – English in this case.
  2. Click on menu selection phpMyAdmin
  3. Under “Create new database”, enter “wordpress” as a name of database in MySQL.
  4. Select utf8_unicode_ci for the collation.
  5. Click on the “Create” button. Your database will be created and a success message will get displayed.

xampp_browser_phpmyadmin_db
Step3:

Installing database for WordPress

Once you’ve got your database setup, you can download WordPress here. Unzip the contents to the C:\xampplite\htdocs folder.

Open the file C:\xampplite\htdocs\wordpress\wp-config-sample.php in a text editor and change the following:

These are the exact details you need for Xampp to work because the default user in phpmyadmin is called ‘root’ and there is no password.

  1. define(’DB_NAME’, ‘wordpress’); // The name of the database
  2. define(’DB_USER’, ‘root’); // Your MySQL username
  3. define(’DB_PASSWORD’, ”); // …and password
  4. define(’DB_HOST’, ‘localhost’); // 99% chance you won’t need to change this value
  5. Copy those details into your wp-config file, and save it as wp-config.php

Close and save this file as wp-config.php

Browse to http://localhost/wordpress/wp-admin/install.php,
You should see a WordPress install screen like this.

wordpress_login

Type in a blog title and provide your email address and click “Install WordPress”. The next screen will display login and password. Write this information down and click on “log in”.

After logging in you’ll be at your “Dashboard”. Click on “View site” next to the title of your blog for a quick, default view of your blog. With the default install of WordPress comes two themes – WordPress and WordPress Classic. Both located under the “Presentation” menu.

Note:

You do not need to use the inbuilt editor to change any WordPress files. Just open them directly in any text editor, make changes and then save.

Filed under: Featured, OpenSource, Web Design, Web Dev