Bootstrap Templates Bundle

Wednesday, April 17, 2013

Display Category in a Dropdown Menu

Some blogs have a lot of categories which they can’t display in their sidebar. Or some bloggers do not want to take up a lot of space displaying categories. This option allows them to have a select menu, dropdown menu, for categories. See WordPress Codex for details.

<form action="<?php bloginfo('url'); ?>/" method="get">
$select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
<noscript><input type="submit" value="View" /></noscript>

Exclude Certain Categories from Being Displayed in a Loop

Your blog page shows recent posts from all categories. If you want to have a separate page for some reason, or do not want to display certain categories, you can use the following code, and it will exclude a certain category from being displayed in a Loop. Just change the category IDs.

<?php if ( have_posts() ) : query_posts($query_string .'&cat=-13,-26'); while ( have_posts() ) : the_post(); ?>

Display Certain Categories in a Menu

In many cases, users only want to display certain categories in their navigation menu at the top of the page. There are limited spots, that can only be filled by top categories, but if you use the default wp_list_categories code, it will show all categories. This is why this hack below comes in very handy when you want to create a navigation menu and only display certain categories.

<ul class="navmenubar" style="float:left; width:730px;">
<?php wp_list_categories('orderby=name&include=7,9,19,16,1,5,17,23'); ?>

Note, you can also change the ‘include’ text to ‘exclude’ and show all categories and exclude those that you don’t want displayed. The numbers displayed in the code are the category IDs. Remember since WordPress shows categories in a list format, you will need to edit the CSS in order to make it work.

Sunday, April 14, 2013

Insert Ads within your Post Content in WordPress

Technic 1:

Copy and paste the following code into your theme’s functions.php:

function inject_ad_text_after_n_chars($content) {
  // only do this if post is longer than 1000 characters
  $enable_length = 1000;
  // insert after the first </p> after 500 characters
  $after_character = 500;
  if (is_single() && strlen($content) > $enable_length) {
    $before_content = substr($content, 0, $after_character);
    $after_content = substr($content, $after_character);
    $after_content = explode('</p>', $after_content);
    $text = '
      <!-- PUT YOUR AD HERE -->
    array_splice($after_content, 1, 0, $text);
    $after_content = implode('</p>', $after_content);
    return $before_content . $after_content;
  else {
    return $content;
add_filter('the_content', 'inject_ad_text_after_n_chars');


Make sure to replace “PUT YOUR AD HERE” with your advertisement code.
$enable_length: Your ad will only be inserted if the post length exceeds this value.
$after_character: Your ad will be inserted after the first </p> after this value.

Technic 2:
Open your theme’s functions.php or a site-specific plugin file and paste the following code:

//Insert ads after second paragraph of single post content.

add_filter( 'the_content', 'prefix_insert_post_ads' );

function prefix_insert_post_ads( $content ) {
	$ad_code = '<div>Ads code goes here</div>';

	if ( is_single() && ! is_admin() ) {
		return prefix_insert_after_paragraph( $ad_code, 2, $content );
	return $content;
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
	$closing_p = '</p>';
	$paragraphs = explode( $closing_p, $content );
	foreach ($paragraphs as $index => $paragraph) {

		if ( trim( $paragraph ) ) {
			$paragraphs[$index] .= $closing_p;

		if ( $paragraph_id == $index + 1 ) {
			$paragraphs[$index] .= $insertion;
	return implode( '', $paragraphs );

To add your ad code, simply edit $ad_code value where it says “Ad code goes here” on line 9. Once you do that, you are done. To change the paragraph number, simply change the number 2 to another paragraph number on line 12.
We hope that this article helped you insert ads within your post content in WordPress. You can re-use this function to add other items for example another ad after the seventh paragraph or so on.
Technic 3:

Display ads on the sidebar

  • Open Dashboard. Choose Appearance > Widgets.
  • Drag the 'Text' widget from the Available Widgets to the Sidebar section.
  • Open the 'Text' widget in the Sidebar. Paste AdSpeed's serving code in the content area. ClickSave.

Display ads only on the homepage

You would use the condition tag is_home() in the homepage.php (or index.php).
<?php if(is_home()) { ?>
<?php } ?>

Display different ads for each content category

Our system is very flexible in the way you sell and organize ads. In WordPress, you would need to use is_category(). These are several methods to organize the ads:
1. One zone per category
You can create multiple zones, one for each category and get the serving code for the zone to put into the WordPress template. Any/all ads linked to this zone will get served in the category. This is the easiest solution to setup and manage. However, if you have many many categories then setting up the first time might take some time. To address this labor-intensive operation, you can use our API (application programming interface) to create the zones in batch.
2. URL targeting
You can create a few zones based on ad location (eg: top, right, bottom) that are shared across categories. The ads linked to these zones then have URL targeting. For example: only display AdA when the URL has "CategoryABC"). This requires that the URL follows a pattern that contains the defined category.

Display category ads on an article/post

If a post is placed in one or more categories, you might want to display ads only for these categories. You would need to edit the single.php template file and use the function in_category() to check if the post is linked to certain categories.

<?php if (in_category('Travel')) { ?>
  [Serving Code for Category/Zone Travel]
<?php } ?>

Sunday, April 7, 2013

Auto install plugins on theme activation or Bundling Plugins with Themes

If any one wants to add a plugins with his theme, below steps will help him

1. At first download a plugins which you want to add with your theme ,suppose facebook-like-box-widget

2.Make a folder, suppose iclt, and put the plugins file into your iclt folder

3. Then In the ‘functions.php’ file of the template add this line at the end:

               include TEMPLATEPATH . '/iclt/facebook-like-box-widget.php';

4. That's all , check your widget options. There you can find the facebook-like-box-widget

Wokiee React eCommerce Template