Saturday, November 19, 2011

show data inside cdata section xml

To show data inside CDATA section in xml from PHP.

if you use this type of xml file

<row no="1">
<DL val="ID">474692000000048282</FL>
<DL val="Name">
<![CDATA[ Marion Center ASD ]]>
<row no="2">
<DL val="ID">474692000000048280</FL>
<DL val="Name">
<![CDATA[ Franklin Regional School District ]]>

$xml = simplexml_load_file('filename');

foreach($xml->Data->row as $row) {
echo "<ul><li>".$row->DL[1]."</li></ul>";

All Done..

Tuesday, July 19, 2011

IP Block contribution

To block some ip address for our site in oscommerce. i have created a simple contribution.
To download the contribution click the link below -

download from here

Monday, June 27, 2011

get user city location

Create function in your controller file..

function _get_location()
        $_country = explode ("\n", $country);
        $_country = str_replace("City: ", "", $_country);
        return $_country[1];

and call this function like this in your controller.

<?php echo $this->_get_location(); ?>

This will give user's location based on its IP address.

Sunday, June 19, 2011

post without image

place this code in functions.php in your theme folder.
function post_without_image($content) {
    echo $content;
    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
    return $postOutput;

use post_without_image() function with 1 parameter with your content anywhere you want

<?php echo post_without_image($content); ?>

Instead of $content we use content variable where we store our content section. That's done.

Get post by category

Sometime we need get post by category in wordpress. Then just create a functions in functions.php in your theme folder with this line..

function get_post_by_category($category_id) {
    global $post;
    $args = array( 'numberposts' => 1, 'category' => $category_id );
    $myposts = get_posts( $args );
    return $myposts;

And use this code where you want to show your post with categories id.

<?php echo get_post_by_category($id); ?>

Instead of $id we use category id. That's all

Thursday, June 16, 2011

Display all images in your site

Copy this code to functions.php

function latest_images() {   
    $images = get_children( 'post_type=attachment&post_mime_type=image&numberposts=3&order=DESC&post_parent=' );
    echo "<ul>";
    foreach($images as $image) {
        echo "<li><a href='" . get_permalink($image->ID) . "'><img src='" . $image->guid . "' width='252' height='135' /></a></li>";   
    echo "</ul>";

and place this to your index.php

<?php latest_images(); ?>

Wednesday, May 11, 2011

Dealer's locator contribution

Hey I have created a simple Osommerce Dealers Locator contribution which locate the dealers.
You can download the contribution from here-

download from here

Put shopping cart code in header Oscommerce

Just put this code into your header.php file..

<a href="<?php echo tep_href_link(FILENAME_SHOPPING_CART); ?>"><?php
  echo $cart->count_contents() . ' Items'; ?></a>

Saturday, April 30, 2011

Insert Google Translater tool into your website

Add Google's website translator to your webpages, and offer instant access to automatic translation of the pages. Adding the website translator is quick and easy.

Just you need to copy and paste these code into your webpage where you want a translater tool.

<div id="google_translate_element"></div>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    includedLanguages: 'af,sq,ar,be,bg,ca,zh-CN,zh-TW,hr,cs,da,nl,en,et,tl,fi,fr,gl,de,el,ht,iw,hi,hu,is,id,ga,it,ja,ko,lv,lt,mk,ms,mt,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sw,sv,th,tr,uk,vi,cy,yi',
    layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
  }, 'google_translate_element');

<script src=""></script>
Enjoy the google translater tool...

Thursday, April 21, 2011

session_register() is deprecated in oscommerce

Just open sessions.php file inside

And find this line -
return session_is_registered($variable);

And replace with this line -
if (PHP_VERSION < 4.3) {
return session_is_registered($variable);
} else {
return isset($_SESSION) && array_key_exists($variable, $_SESSION);

Reload window javascript

<head><title>Reload Script</title>
<script type="text/javascript">
function reloadPage() {
<input type="button" value="Reload Page" onclick="reloadPage()">

Saturday, April 9, 2011

Jquery Confliction with Plugin

when some jquery developers written or used same function name or same methods then jquery conflicts is happening. In wordpress when jQuery confliction occured than some plugin's with jquery not work perfectly. You could try to execute your jquery with a noConflict option -

<script type="text/javascript">
var j = jQuery.noConflict();
j("div p").hide();
$("content").style.display = 'none';

Use this javascript code after <?php wp_head(); ?> code in the header.php file in your theme folder.
And add below line in your functions.php in your theme folder.

function my_init_method() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'wp-content\themes\thebusinessoctopus-wordpress-theme\images\slideshow\js\jquery.js');
        wp_enqueue_script( 'jquery' );

add_action('init', 'my_init_method');

That's all done..

Friday, April 8, 2011

Show some line of content with Read more

Show some lines of huge content with Read more link in php

$content = "Integer pretium vehicula molestie. Nunc nec enim dui, sit amet auctor mauris. Integer in urna vel magna elementum fermentum. Integer a sem in mi eleifend adipiscing. Pellentesque ultrices egestas adipiscing. Nulla placerat enim at lorem ornare sed cursus mauris fringilla. ";

echo substr(strip_tags($content), 0, 100) . "...     " . "<a href='#'>Read more</a>";

Tuesday, March 8, 2011

query_posts() Pagination problem

Find this line in your page.

<?php if (have_posts()) : ?>

And place this code above this code.

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=1&paged=$paged"); ?>

That's done...

Thursday, March 3, 2011

Get the Current Page URL

Insert this code in your php file.

$path = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") +1);
echo $path;

And now preview in your browser it'll show you which page open in your browser

Tuesday, March 1, 2011

Transfer drupal sites to other server..

1) Go to your xampp folder.
2) Apache
3) Conff
4) Open httpd.conff file
5) find this line
      #LoadModule rewrite_module modules/
6) And replace with this
      LoadModule rewrite_module modules/
7) And restart your server.

that's done...

Wednesday, February 23, 2011

Show post with next previous links with jquery wordpress

First you need to download three images and upload it to your theme/images directory..
Here is the images..

second copy this code and paste it in the function.php in your theme directory.

function my_init_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', '');
    wp_enqueue_script( 'jquery' );
add_action('init', 'my_init_method');

if(!function_exists('limit_post')) {
function limit_post($content) {
 $content = get_the_content($more_link_text, $stripteaser, $more_file);
      $content = apply_filters('the_content', $content);
      $content = str_replace(']]>', ']]>', $content);
      $content = substr(strip_tags($content), 0, 50).'…';
      echo $content;

if(!function_exists('content')) {
function content($id=''){
    $single = new WP_Query;
    while ($single->have_posts()) : $single->the_post(); ?>
               <div class="meta">             
               <a href="<?php the_permalink() ?>"><?php limit_post('the_content()'); ?></a>
<?php endwhile;

And place this code where you want to show post links.

<?php if(!is_page()) { ?>
#postPagination {float:left; padding: 3px;}
#postPagination label { color: #a68a5a;}
#contentInner {float: left;  padding: 3px;}
#contentInner a{color:#333333; text-decoration: none; }
#contentInner a:hover {color: #ff4b33; }
<div id="postPagination">
   <label>latest on blog</label>
   <a href="<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>" title="Previous"><img src="<?php bloginfo('template_directory') ?>/images/previous.gif" border="0" /></a>
   <a href="<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>" title="Next"><img src="<?php bloginfo('template_directory') ?>/images/next.gif" border="0" /></a>
<div id="contentInner">
if($_POST['id']) {
} else {
} ?>
<script type="text/javascript" charset="utf-8">

jQuery('#postPagination a').live('click', function(e){
var link = jQuery(this).attr('href');
var id = link.split("=");
return "<img src='<?php bloginfo('template_directory') ?>/images/loading.gif' />"
jQuery('#contentInner').load(link+' #contentInner', {id:id[1]});
jQuery('#postPagination').load(link+' #postPagination');
<?php } ?>

Computer automatically start with safe mode

Sometimes PC automatically start with safe mode to resolve this problem just follow these steps..

1) Go to start
2) Click Run
3) type msconfig
4) Click the boot tab
5) Uncheck the safe boot option

That's it...

Monday, February 7, 2011

WordPress Post List With Thumbnails

The function bellow, shows a list with posts and custom size thumbnails(for the post first image), linked to each post permalink. First copy this code and paste it in the function.php in your theme directory.

function thumb($id)
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $id
$attachments = get_posts($args);
// here we set the variable for the attachment string
$imgsrc = "";
if ($attachments):
// here we take the first image and break the loop
foreach ($attachments as $attachment) {
// this brings the attachment array $imgobj = wp_get_attachment_image_src($attachment->ID);
// if you use the line obove, you can call $imgobj[0] to get the image source
// you can set the thumbnail dimensions, here we use 40 x 40
$imgsrc = wp_get_attachment_image($attachment->ID, array(150,100), $icon = false);
return $imgsrc;

Call the function in your index.php or home.php ..

<a href="<?php the_permalink() ?>"><?php echo thumb($post->ID); ?></a>

That's all done..

Wednesday, February 2, 2011

Character Limit (Pages & Posts) content

Just open your home.php. This file is located in your theme folder. Open this file with your text editor.

find this line in your home.php file -

<?php the_content('Read the rest of this entry &raquo;'); ?>

Replace with this

$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo substr(strip_tags($content), 0, 250).'…' ; 

Now do same with your index.php file.
That's all...

Thursday, January 13, 2011

post data to other pages by ajax

Example :-
          //do something with result.

receive.php is a url where request is sent.
$('form1').serialize() is used to send the form1 data to the server with the request.
result it returns the result from the receive.php file.