Skip to content

Category: Coding

Programming and scripting topics.

How to add extra sidebar to a WordPress theme?

To begin the tutorial, extract your theme into a folder and open it to see all the files. If your theme has only one sidebar, then most probably you will NOT find a file called functions.php in your theme folder. In that case you will have to create this file yourself. Just open notepad or any other code editor to start a new file. Put this code into that file:

Problem with category slug renaming in WordPress

I had a problem. I couldn’t change the category slug in some of my categories. So I found the solution at:

http://wordpress.org/support/topic/category-slug-cant-be-updated

The problem comes from the fact that the tags and categories are stored in the same table in the database. And the tags also have slugs. So if there is already a tag with the slug that you want to put in the category you can’t do it until you delete the tag or change it’s slug.

You just need to go to the tags table in the admin panel and change the tag slug that’s making the problem.

How to remove “View Full-Size Image” text link in Virtuemart product description?

One way to remove the text “View Full-Size Image” from beneath your product thumbnail on your flypage, make a copy of, then edit this file:

components/com_virtuemart/themes/your_theme/theme.php

Find the function vmBuildFullImageLink and within that find this line:

Code: [Select]
$text = ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0)."<br/>".$VM_LANG->_('PHPSHOP_FLYPAGE_ENLARGE_IMAGE');

Change it so it looks like this:

Code: [Select]
$text = ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0);

Save and test.

Another method would be to clear out the ‘PHPSHOP_FLYPAGE_ENLARGE_IMAGE’ text in your langauge file.

Using the Page Class Suffix in Joomla templates and components

Load Suffix

First, we need to find out what the page class suffix is for the page we are visiting. To do this, you will need add some code to your template:

  1. Open your template’s index.php file (located in /templates/*template-name*/)
  2. Find the <head> tag in the index.php, near the top area of the template
  3. Above this, insert one of the following code blocks (Either of the following options will work fine in most cases. However they work slightly differently, so in certain cases your needs may dictate a specific choice.)

By Itemid

To load the page class suffix associated with the current Itemid, add this to the top of the index.php file:

<?php
  $itemid = JRequest::getVar('Itemid');
  $menu = &JSite::getMenu();
  $active = $menu->getItem($itemid);
  $params = $menu->getParams( $active->id );
  $pageclass = $params->get( 'pageclass_sfx' );
?>

By Active Menu Item

To load the page class suffix associated with the active menu item, add this to the top of the index.php file: (For sub-pages with no active menu item, this will load the page class suffix for the default menu item.)

<?php
   $menus      = &JSite::getMenu();
   $menu      = $menus->getActive();
   $pageclass   = "";

   if (is_object( $menu )) :
   $params = new JParameter( $menu->params );
   $pageclass = $params->get( 'pageclass_sfx' );
   endif; 
?>

(credit: Page Class Suffix in template code)

Security

You should always use htmlspecialchars() in your code before writing something into an HTML attribute, else you open up an attack vector to inject script code into your page.

Insert Suffix

The next step is to use the page class suffix somewhere in the template.

In the Body Tag

The more common method would be to apply the page class suffix as an id or class to the <body> tag. Find the <body> tag (below the </head> tag) and replace it with this:

<body id="<?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?>">

To Load a Page-Specific Stylesheet

The second method would be to load a stylesheet unique to the page in question. Instead of modifying the <body> tag, look for the stylesheet link within the <head></head> tags and add the following line directly beneath it:

<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/<?php echo htmlspecialchars($pageclass) ?>.css" type="text/css"/>

For more info: http://docs.joomla.org/Using_the_Page_Class_Suffix_in_Template_Code

HTML javascript popup window

This is the code:

<a onclick="window.open(this.href,'win2','width=400,height=350,menubar=yes,resizable=yes'); return false;" title="Your Title" href="yourlink.com">some text</a>

How to put a sound on your website?

I use flash to achieve this. Create a new flash file with AS3. Create two buttons which will be placed one above the other. The stop button instance is called xstop and the play button instance is called xplay.

And this is the code:

//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("http://www.kavdesign.net/sites/stgeorge/birds1.mp3"));

xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlay);

playMusic();

function clickPlay(evt:MouseEvent) {
	playMusic();
}

function clickStop(evt:MouseEvent) {
		soundChannel.stop();
		soundChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
		xstop.visible = false;
		xplay.visible = true;
}

function playMusic():void
	{
		 soundChannel = sound.play();
		 soundChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
		 xstop.visible = true;
		 xplay.visible = false;
	}

function loopMusic(e:Event):void
	{
		 if (soundChannel != null)
		 {
			  soundChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
			  playMusic();
		 }
	}

How to add a 1px border to a table with CSS?

Problem

I want to have a one-pixel one-color solid border around a table and its cells. Adding border="1" to the table tag isn’t suitable, because it looks horrific in most of the browsers.

Solution with HTML only

Back in the old days we used to use just HTML to create a one-pixel border. Some people even used 1×1 pixel transparent gifs, but let’s not go into that. The easiest way to achieve the border was to use nested tables: outer table that provides the border color and inner table that holds the content.

Here’s an example:

Cell 1 Cell 2
Cell 3 Cell 4

Looks pretty fine, doesn’t it? However, let’s look into the code:

WordPress Facebook like button plugin doesn’t show on category and tag pages

I’m using this one:

FaceBook Like Button Plugin for WordPress

by http://healyourchurchwebsite.com/2010/04/22/the-facebook-like-button-plugin-for-wordpress/

But there in one limitation. It doesn’t show the button on the category archive view and on the tag archive view pages. Probably in some cases it is good, but in others it’s better to show it.

So in order to do this go to the plugin files and open fblike_content_filter.php

On line 12 there is:

if(     (is_front_page() && $fblike_settings_show_on_front_page == 'true') ||
 (is_single() && $fblike_settings_show_on_single_post == 'true') ||
 (is_page() && $fblike_settings_show_on_single_page == 'true') )
 {

Add two more lines so it will become like this:

if(     (is_front_page() && $fblike_settings_show_on_front_page == 'true') ||
 (is_single() && $fblike_settings_show_on_single_post == 'true') ||
 (is_category() && $fblike_settings_show_on_front_page == 'true') ||
 (is_tag() && $fblike_settings_show_on_front_page == 'true') ||
 (is_page() && $fblike_settings_show_on_single_page == 'true') )
 {

Additional info on the WordPress conditional tags can be found here:
http://codex.wordpress.org/Conditional_Tags