Posts Tagged ‘how to’


WordPress Hack – How to Insert Ads in the Middle of Your Content!

With this hack you will be able to add adsense block (or somethings else) in the midde of your post after 2 paragraphs.

As a hard hack my suggestion is make a template backup before apply this tricks.

  • Open your “single.php” file (in your template folder)
  • Search
    <?php the_content(); ?>
  • Replace with:
    <?php
      $content = apply_filters('the_content', $post->post_content);  //get the post content store in $content
      $save = explode("</p>", $content);  //Separate the content into <p> blocks
      $tcount=0; //this is count for number of <p> blocks
      $adon=0;  //this is a variable so you don't show ads more than once.
      foreach($save as $item) {
        echo $item;  //print the <p> block
        echo "</p>"; 
        if(preg_match('/<p> /',$item)==0 && $tcount>=1 && $adon==0) {
                                    $adon=1;
    ?>
    Replace this with Your adsense code!!!
    <?php
        }
     if(preg_match('/<p> /',$item)==0 && $tcount>=4 && $adon==1) {
                                    $adon=2;
    ?>
    Replace this with Your adsense code if you want additional adsense blocks for super long blog posts or leave it empty if you don't want one.
    <?php
       }
       $tcount++;
     }
    ?>
    

    credit goes to : zedomax.biz


How to display post count from a category

I am just recording my work right now. I found this to work really well.

function wt_get_category_count($input = '') {
global $wpdb;
if($input == '')
{
$category = get_the_category();
return $category[0]->category_count;
}
elseif(is_numeric($input))
{
$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
return $wpdb->get_var($SQL);
}
else
{
$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
return $wpdb->get_var($SQL);
}
}

Place above in your function.php file.

And then add below inside the regular php begin and end to any location you want the count to be displayed.
echo wt_get_category_count(categoryid);

Thanks to WPCode.net

Insert Your Recent Comments from Facebook to Database

The sample is for scraping data from Facebook home page. Once you will pass your username and password in variables  i have declared in file and execute the code you will get your home page of Facebook.

Here php code will pass the variables by POST method to https://login.facebook.com/login.php page and login into facebook account then other curl call will call my home page to get the home page HTML.

I have written code of how i am scrapping data by DOM Parser.

<?PHP
$first_name = 'First Name';
$login_email = 'facebookloginemail';
$login_pass = 'password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);

/*
Here it will print the facebook home page with your recent updates
*/

echo $page;

// Parse the HTML information and return the results.
$dom = new DOMDocument();
@$dom->loadHtml($page);

$xpath = new DOMXPath($dom);

// Get a list of articles from the section page

$articleList = $xpath->query("*/div[@id='m_stream_stories']");
print_r($articleList);

// Add each articles url to the Articles array
// This way we can scrap any part of data of any sites.

$articles = array();
foreach ($articleList as $item){
	$articles[] = array(
								'url' => $item->getElementsByTagName('a')->item(0)->getAttribute('href')
					   );
}

print_r($articles);

// Here we can loop for the article array and insert it into database.
?>

If you have any trouble in getting it work let me know i will help you.

Update Your Facebook Status By PHP Script

Hey would you like to update your facebook status, but don’t want to go to facebook.com, login, and finally being able to update your status?
Then Do one thing simply save the following code on your server, define the variables and Rock :)

<?PHP
/*******************************
*	Facebook Status Updater
*	Christian Flickinger
*	http://nexdot.net/blog
*	April 20, 2007
*******************************/

$status = 'YOUR_STATUS';
$first_name = 'YOUR_FIRST_NAME';
$login_email = 'YOUR_LOGIN_EMAIL';
$login_pass = 'YOUR_PASSWORD';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 1);
preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
curl_exec($ch);
?>

source : http://codesnippets.joyent.com/posts/show/1204

source:stackoverflow.com
Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories