Totally dynamic WordPress sidebars
Thursday 31st December 2009 by admin
Many of us are blogging on different subjects, usually we call them categories, ours are Blogging, Functions & tips, Social media etc.
How often do we want different content in the sidebar/s. Content that relates to a specific category? This question was also raised by a client – Want WordPress, but want different content in the sidebars.
OK. no problem here is the way to do it. You can create as many totally dynamic sidbars as you want based on categories/ pages even tags. The example below works on categories, creating a sidebar for each category that can hold different content.
Lets look at the standard default function page – function.php open it up and you will see:
-
-
‘before_widget’ => ‘<li id="%1$s" class="widget %2$s">’,
-
‘after_widget’ => ‘</li>’,
-
‘before_title’ => ‘<h2 class="widgettitle">’,
-
‘after_title’ => ‘</h2>’,
-
));
-
}
-
Found it, great, this is the WordPress/php function that allows you to put widgets into the sidebar. But did you know you can ‘name’ the sidebars.?
This is an example of extending the WordPress function above for 2 sidebars:
-
-
-
‘before_widget’ => ‘<li id="%1$s" class="widget %2$s">’,
-
‘after_widget’ => ‘</li>’,
-
‘before_title’ => ‘<h2 class="widgettitle">’,
-
‘after_title’ => ‘</h2>’,
-
));
-
-
‘before_widget’ => ”,
-
‘after_widget’ => ”,
-
‘before_title’ => ”,
-
‘after_title’ => ”,
-
));
-
-
}
-
These functions create the functionalities for 2 different sidebars – sidebar_no1 and sidebar_no2. All that you then need to do is create the sidebar templates.
Open the default sidebar.php and you will see this (line 10)
-
-
// and at the bottom of the page about line 80 you will see
-
<?php endif; ?>
-
OK, this works for the standard sidebar template but not for 2 different sidebars – sidebar_no1 and sidebar_no2. To create that functionality you need to change the code on the fist page to:
-
-
-
‘before_widget’ => ‘<li id="%1$s" class="widget %2$s">’,
-
‘after_widget’ => ‘</li>’,
-
‘before_title’ => ‘<h2 class="widgettitle">’,
-
‘after_title’ => ‘</h2>’,
-
));
-
}
-
Volia you now have 2 sidebars each of which will allow you to add different widgets.
Only one problem the second sidebar – sidebar_no2 – is not included in your theme templates. Why all this to get so ar but not be able to use the code – well it explains the principles of what comes next.
Lets create totally dynamic side bars for each category in your blog.
This WordPress query allows you to get/obtain all the category names:
-
-
$qtable1=$wpdb->prefix . "term_taxonomy";
-
$qtable2=$wpdb->prefix . "terms";
-
$sql = "SELECT * FROM $qtable1 LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id) = ($wpdb->term_taxonomy.term_id) WHERE ($wpdb->term_taxonomy.taxonomy = ‘category’) AND ($wpdb->term_taxonomy.parent = ‘1′)";
-
$categories = $wpdb->get_results($sql);
-
Now we add the sidebar function (above)
-
-
-
foreach ($categories as $category) :
-
-
‘before_widget’ => ‘<li id="%1$s" class="widget %2$s">’,
-
‘after_widget’ => ‘</li>’,
-
‘before_title’ => ‘<h2 class="widgettitle">’,
-
‘after_title’ => ‘</h2>’,
-
));
-
endforeach;
-
In this query $category->name gives you the category name.
Now return to the file sidebar.php and add a bit of code:
-
-
-
endif;
-
And at the top of the page use a conditional WordPress query as above
-
-
$category = get_the_category();
-
$categoryname=‘ ‘;
-
else:
-
$categoryname=$category->category_name;
-
endif;
-
By doing that you can display the different sidebars for each category from a single sidebar page.
I have tried to keep this as a simple and easy to follow example without going into too much detail. This functionality can be greatly expanded – as we have done on a number of sites. Easy for the user, easy to administer and gives you great flexability with sidebars.
Once again hope this helps
Popularity: 8% [?]
WordCamp Kefalonia
Wednesday 30th December 2009 by admin1
COMMENTS
18 – 20 June 2010 a WordCamp with a difference on a Greek Island – Kefalonia, actually Agia Efimia (Kefalonia).
Full details of the key-note speakers (and there will be some “real” key-note speakers i.e. people who really know things and you may well of heard of them to!) will be released shortly, but we thought you might like to know about WordCamp Kefalonia.
We are well aware that holding a WordCamp on a Greek Island in a small fishing village rather than a larger provincial town – is – shall we say different – but Kefalonia has a lot to offer it’s visitors and there is some great WordPress work being carried out here – beleive it or not.
For those who don’t know, WordCamp(s) are conferences that focuses on everything WordPress. WordCamps are informal, community-organized events that are put together by WordPress users like us. Everyone from casual users to core developers participate, share ideas, and get to know each other. WordCamps are open to WordPress.com and WordPress.org users alike.
We aim to make WordCamp Kefalonia different and appealing to a wide variety of people. Already we have had expressions of interest in attending from Canada, the USA and Switzerland and obviously Kefalonia but it is this international twist that is making us push ahead with WordCamp Kefalonia.
We acknowledge that WordCamp Kefalonia – 2010 – may not be a large scale event that will register on everybodies radar but we intent to build on 2010 in 2011 and onwards. Our reason for this is two fold, it helps to promote Kefalonia as a destination which can only be good for the local businesses but it will also help with the promotion of the internet here on the island.
Whilst that may sound strange in areas of mass habitation like America and mainland Europe, Kefalonia is a Greek Island the derives 80% of it’s ‘island’ GDP from tourism between May and October – the island virtually shuts after the season. The promotion of tourism via the internet is important to many businesses here and an obvious extension the populations welfare – given the relience on tourism – but to date most have not been given the opportunity to explore real internet marketing, B2B or E-Commerce, factors that could have a dramatic effect. Further, many people are seeking more knowledge about the internet and how it can work in their favour.
WordCamp Kefalonia will help far beyond those who attend.
WordCamp Kefalonia will be an English language event not a Greek langauge event though we will provide translation. We are also hopeful to provide translations into Italian, German and French.
If you would like to be kept up to date on WordCamp Kefalonia don’t forget to keep comming back (here) and to subscribe to the RSS feed. You can also let us have your comments and thoughts on the WordCamp page:
Popularity: 7% [?]
WordPress related posts function
Monday 28th December 2009 by admin0
COMMENTS
Here is today’s addition to WordPress functions & tips – a quick way to add a simple related WordPress posts function without the need for a WordPress plugin.
This function works by linking the tags on a single page or single post page and can be used anywhere outside the loop e.g. the sidebar.
Firstly declare a global variable based on the post ID
-
-
global $constant_post_id;
-
$constant_post_id = $post->ID;
-
Use the wp_get_object_terms to get the post tags realting to the post in question
-
-
$tags = wp_get_object_terms($constant_post_id, ‘post_tag’);
-
Start a foreach statement based on each tag
-
-
foreach ($tags as $tag) :
-
$tag_content = $tag->slug;
-
// Show the tag name if you wish //
-
// Start an unordered list //
-
echo ‘<ul>’;
-
Get the tag ’slug’ as this is used in the following get_posts query
-
-
$tag_slug = $tag_content;
-
Now run a get_posts using the $tag_slug (above) and the post->ID which we decalred as a global in section 1
-
-
$relatedposts = get_posts(‘tag=’.$tag_slug.‘&exclude=’.$constant_post_id.”);
-
foreach(relatedposts as relatedposts) :
-
setup_postdata(relatedposts);
-
endforeach;
-
// end the unordered list – if you are using one //
-
echo ‘</ul>’;
-
endforeach;
-
And don’t forget to reset the query
-
-
wp_reset_query();
-
Voila a related posts query based on WordPress tags. All that is left is to make it a function ready to past into your functions.php file so you can simply use it anywhere you want here goes:
-
-
function my_related_posts() {
-
global $constant_post_id;
-
$constant_post_id = $post->ID;
-
$tags = wp_get_object_terms($constant_post_id, ‘post_tag’);
-
foreach ($tags as $tag) :
-
$tag_content = $tag->slug;
-
// Show the tag name if you wish //
-
// Start an unordered list //
-
echo ‘<ul>’;
-
$tag_slug = $tag_content;
-
$relatedposts = get_posts(‘tag=’.$tag_slug.‘&exclude=’.$constant_post_id.”);
-
foreach(relatedposts as relatedposts) :
-
setup_postdata(relatedposts);
-
endforeach;
-
// end the unordered list – if you are using one //
-
echo ‘</ul>’;
-
endforeach;
-
}
-
So to use this function all you need to do is call my_related_posts();
Hope this helps
Popularity: 10% [?]
Serious about blogging?
Thursday 24th December 2009 by admin0
COMMENTSAs WordPress theme developers we see many WordPress backends. We see the posts that people make when blogging and we see the mistakes so often made.
Nearly all our Clients want “top of Google” but don’t help themselves with their own SEO – search engine optimization – when blogging. WordPress theme developers can only do so much by pointing you in the right direction.
Todays WordPress tip is short and sweet.
When blogging help yourself with your own SEO and internet marketing.
- Don’t forget to use the WordPress excerpt function, create good page titles – we worked on a 24 page blog last week with 10 pages that had not title.
- Look at using a SEO plugin like Meta SEO pack to create page descriptions and keywords for posts and pages.
- Use inter page/post links – look at this tip a WordPress function to create automatic links for category names in the content of posts.
- Remember your tags.
- Tell people you have posted – share your thoughts via your social media outlets like Twitter, Facebook and MySpace
Popularity: 2% [?]
Increase font size on the page with JQuery
Wednesday 23rd December 2009 by admin0
COMMENTS
Giving visitors to your site the ability to increase font size on the page – it’s available in most browsers tool bars – is one way to help accessibility and usability on your blog / site.
It can be easily achieved using a small bit of JQuery. Sounds complex, but with JQuery already built into WordPress all you need do is add this function into the header file (code setion 1) and add a little bit of text and CSS – (code section 2)
Code section 1
-
$(document).ready(function(){
-
-
// Reset Font Size
-
-
var originalFontSize = $(‘html’).css(‘font-size’);
-
-
$(".resetFont").click(function(){ $(‘html’).css(‘font-size’, originalFontSize); });
-
-
// Increase Font Size
-
-
$(".increaseFont").click(function(){
-
-
var currentFontSize = $(‘html’).css(‘font-size’);
-
-
var currentFontSizeNum = parseFloat(currentFontSize, 10);
-
-
var newFontSize = currentFontSizeNum*1.2;
-
-
$(‘html’).css(‘font-size’, newFontSize);
-
-
return false;
-
-
});
-
-
// Decrease Font Size
-
-
$(".decreaseFont").click(function(){
-
-
var currentFontSize = $(‘html’).css(‘font-size’);
-
-
var currentFontSizeNum = parseFloat(currentFontSize, 10);
-
-
var newFontSize = currentFontSizeNum*0.8;
-
-
$(‘html’).css(‘font-size’, newFontSize);
-
-
return false;
-
-
});
-
-
});
-
Code section 2
-
-
<div id="textsizing">
-
-
Font size:
-
-
<a class="increaseFont" title="Make text larger" href="#">Increase</a>
-
-
<a class="decreaseFont" title="Make text smaller" href="#">Decrease</a>
-
-
<a class="resetFont" title="Return to default size" href="#">Reset</a></div>
-
-
Once again, hope this helps
Popularity: 4% [?]



0
COMMENTS