Wednesday, May 23, 2012

Change date to timestamp PHP

Change normal date to timestamp

$timestamp = strtotime(date("D M d, Y G:i:s a"));

Hack google-sitemap-generator for my custom sitemaping

Just Open Your google-sitemap-generator Plugin Directory. And open sitemap-core.php file

find this :-

$this->AddUrl($page->GetUrl(), $page->getLastMod(),$page->getChangeFreq(),$page->getPriority());

And Below after ending second '}' (Curlibraces) you write down your code like that:-

$rows = $wpdb->get_results( "SELECT id, last_access FROM TABLE ORDER BY id ASC" );
foreach($rows as $row) :
$the_page = get_page_by_title( 'PAGE_TITLE' );
$GetUrl = add_query_arg(array('id' => $row->id), get_permalink($the_page->ID));
$lastMod = strtotime($row->last_access);
$this->AddUrl($GetUrl, $lastMod, 'Weekly', 0.6);
endforeach;

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

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

<?php
$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..

<?php
function _get_location()
    {
        $country=file_get_contents('http://api.hostip.info/get_html.php?ip=');
        $_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.
<?php
function post_without_image($content) {
    ob_start();
    echo $content;
    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
    ob_end_clean();
    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..

<?php
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