To Set Breadcrumb to Taxonomy Programmatically.
Add this code in Template.php
function theme_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
$cat = taxonomy_get_term(arg(1)) ;
if(taxonomy_get_parents($cat->tid) == array()) {
$breadcrumb[] = l($cat->name , str_replace(" ","-",(strtolower($cat->name))));
}
else {
$parent_term = taxonomy_get_parents($cat->tid);
foreach($parent_term as $key => $value){
$name = $parent_term[$key]->name;
}
$breadcrumb[] = l($name , str_replace(" ","-",(strtolower($name))));
$breadcrumb[] = l($cat->name , str_replace(" ","-",(strtolower($name))."/".str_replace(" ","-",(strtolower($cat->name)))));
}
}
}
Drupal and PHP related posts - Drupal Chennai, Navaneethakrishnan.R
Wednesday, January 28, 2009
Tuesday, January 27, 2009
Drupal view count result
Code to drupal view count result
<?php
// Lift the globals into local scope to save typing $GLOBALS[''] every time...
global $pager_page_array, $pager_total_items, $pager_total, $current_view;
if ($pager_total[0] == 1) { // Number of pages == 1
echo "Showing <b>" . $pager_total_items[0] . "</b> results";
}else{
// Page number is zero-based (first page is 0)
// Multiply pager_limit by page number (eg 0, 15, 30) and add 1 to get first item
$start = 1 + ($pager_page_array[0] * $current_view->pager_limit);
// Multiply pager_limit by page number + 1 (eg 15, 30, 45) to get last item
$end = (1 + $pager_page_array[0]) * $current_view->pager_limit;
// Use total items count if this is less than that
if ($end > $pager_total_items[0]) $end = $pager_total_items[0];
echo "Showing $start-$end of <b>" . $pager_total_items[0] . "</b> results";
}
<?php
// Lift the globals into local scope to save typing $GLOBALS[''] every time...
global $pager_page_array, $pager_total_items, $pager_total, $current_view;
if ($pager_total[0] == 1) { // Number of pages == 1
echo "Showing <b>" . $pager_total_items[0] . "</b> results";
}else{
// Page number is zero-based (first page is 0)
// Multiply pager_limit by page number (eg 0, 15, 30) and add 1 to get first item
$start = 1 + ($pager_page_array[0] * $current_view->pager_limit);
// Multiply pager_limit by page number + 1 (eg 15, 30, 45) to get last item
$end = (1 + $pager_page_array[0]) * $current_view->pager_limit;
// Use total items count if this is less than that
if ($end > $pager_total_items[0]) $end = $pager_total_items[0];
echo "Showing $start-$end of <b>" . $pager_total_items[0] . "</b> results";
}
Monday, January 26, 2009
Floating Search Box in drupal
Code to Float search box in drupal....
Add IN page.tpl.php
<?php if ($search_box): ?>
<div id="float" >
<?php print $search_box ?>
</div>
<?php endif; ?>
Add IN any css file in your theme folder
#floater {
padding-bottom: 10px;
position: relative;
float: right;
margin-top: 10px;
width: 205px;
z-index: 2;
}
Add IN page.tpl.php
<?php if ($search_box): ?>
<div id="float" >
<?php print $search_box ?>
</div>
<?php endif; ?>
Add IN any css file in your theme folder
#floater {
padding-bottom: 10px;
position: relative;
float: right;
margin-top: 10px;
width: 205px;
z-index: 2;
}
Tuesday, January 20, 2009
drupal : count number of tables in database [mysql]
To count the number of tables in mysql database in cutom drupal page.
=======================================================
select count(*) from information_schema.tables where table_schema = 'intr';
=======================================================
=======================================================
select count(*) from information_schema.tables where table_schema = 'intr';
=======================================================
Split the p tag
<html>
<head>
<meta name="description" content="Split the <p> tag into some numbers" />
<meta name="keywords" content="Split the p tag ,Split the p tag using regular expression,Split the p tag using php " />
</head>
<body>
<?php
$inp = '<p>Paragraph1</p><p>Paragraph2</p><p>Paragraph3</p><p>Paragraph4</p><p>Paragraph5</p><p>Paragraph6</p>';
$expression = '/<p>(.*)<\/p>/';
preg_match_all($expression,$inp,$match);
$match = explode("</p><p>",$match[1][0]);
for($i=0;$i<2;$i++){
echo '<p>'.$match[$i].'</p>';
}
echo '=======================';
for($i=0;$i<count($match);$i++){
echo '<p>'.$match[$i].'</p>';
}
?>
</body>
</html>
<head>
<meta name="description" content="Split the <p> tag into some numbers" />
<meta name="keywords" content="Split the p tag ,Split the p tag using regular expression,Split the p tag using php " />
</head>
<body>
<?php
$inp = '<p>Paragraph1</p><p>Paragraph2</p><p>Paragraph3</p><p>Paragraph4</p><p>Paragraph5</p><p>Paragraph6</p>';
$expression = '/<p>(.*)<\/p>/';
preg_match_all($expression,$inp,$match);
$match = explode("</p><p>",$match[1][0]);
for($i=0;$i<2;$i++){
echo '<p>'.$match[$i].'</p>';
}
echo '=======================';
for($i=0;$i<count($match);$i++){
echo '<p>'.$match[$i].'</p>';
}
?>
</body>
</html>
Monday, January 19, 2009
Extract src from IMG tag using regular expression
Here is the code to extract src from IMG tag using regular expression. We can use this also in drupal
------------------------------------------------------------------------------------
<?php
$field_lead_image_fid = '<img src="src.jpg" alt="Get groomed for the industry" title="title" />';
$epression = "/<img src=\"(.*)\" alt=\"(.*)\" title=\"(.*)\" \/>/";
preg_match_all($epression,$field_lead_image_fid,$matches);
echo '<pre>'; print_r($matches); echo '</pre>';
?>
----------------------------------------------------------------------------------
Note:
$epression Order [ src, alt, title] should be same as in $field_lead_image_fid.
------------------------------------------------------------------------------------
<?php
$field_lead_image_fid = '<img src="src.jpg" alt="Get groomed for the industry" title="title" />';
$epression = "/<img src=\"(.*)\" alt=\"(.*)\" title=\"(.*)\" \/>/";
preg_match_all($epression,$field_lead_image_fid,$matches);
echo '<pre>'; print_r($matches); echo '</pre>';
?>
----------------------------------------------------------------------------------
Note:
$epression Order [ src, alt, title] should be same as in $field_lead_image_fid.
Thursday, January 8, 2009
google0e91f60caf156ad3.html
I've uploaded the file to http://navaneethakrishnan-drupal.blogspot.com/ and can view http://navaneethakrishnan-drupal.blogspot.com/2009/01/google0e91f60caf156ad3html.html in my browser.
Subscribe to:
Posts (Atom)