Get Website Lowest price!

Wordpress Experts!

×

php up to date

Wordpress custom posts page with Pagination

Wordpress custom posts page with Pagination 


<?php 

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 5, 'paged' => $paged );
query_posts($args); 

?>
<?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>

<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>

<?php endif; ?>

Customize Login Page

wordpress login page customization


Change the Logo

Is the WordPress logo by default, this changes the file path of that image. Change file path and file name to your own needs.

function custom_login_logo() {
echo '<style type="text/css">h1 a { background: url('.get_bloginfo('template_directory').'/images/logo-login.gif) 50% 50% no-repeat !important; }</style>';
}
add_action('login_head', 'custom_login_logo');
Change the URL

... of where clicking that logo goes. By default it goes to WordPress.org, this will change it to your own homepage.

function change_wp_login_url() {
return bloginfo('url');
}
add_filter('login_headerurl', 'change_wp_login_url');
Change the Title

That is, change the title attribute of the image you just replaced. This changes it to the name of your blog in the settings.

function change_wp_login_title() {
return get_option('blogname');
}
add_filter('login_headertitle', 'change_wp_login_title');

Embed a Page inside a Page

wordpress embed a Page inside a Page



<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_content(); ?>
<?php endwhile; ?>

The above code can be used within the regular page loop. Replace **ID** with the ID of the page you wish to embed.

you could also use “pagename=”

Find All Links on a Page

Find All Links on a Page


$html = file_get_contents('http://www.example.com'); $dom = new DOMDocument(); @$dom->loadHTML($html); // grab all the on the page $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); echo $url.'<br />'; }

Email Address Validation

php Email Address Validation


<?php $email="test@geemail.com"; if (isValidEmail($email)) { echo "Hooray! Adress is correct."; } else { echo "Sorry! No way."; } //Check-Function function isValidEmail($email) { //Perform a basic syntax-Check //If this check fails, there's no need to continue if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } //extract host list($user, $host) = explode("@", $email); //check, if host is accessible if (!checkdnsrr($host, "MX") && !checkdnsrr($host, "A")) { return false; } return true; } ?>


This function doesn't only check if the format of the given email address is correct, it also performs a test if the host is existing.

PHP TIPS AND TRICKS YOU SHOULD KNOW


Check if Website is Available


<?php if (isDomainAvailible('http://www.eightlegbuilders.in')) { echo "Up and running!"; } else { echo "Woops, nothing found there."; } //returns true, if domain is availible, false if not function isDomainAvailible($domain) { //check, if a valid url is provided if(!filter_var($domain, FILTER_VALIDATE_URL)) { return false; } //initialize curl $curlInit = curl_init($domain); curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($curlInit,CURLOPT_HEADER,true); curl_setopt($curlInit,CURLOPT_NOBODY,true); curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true); //get answer $response = curl_exec($curlInit); curl_close($curlInit); if ($response) return true; return false; } ?>

Method #2

<?php ini_set("default_socket_timeout","05"); set_time_limit(5); $f=fopen("http://www.css-tricks.com","r"); $r=fread($f,1000); fclose($f); if(strlen($r)>1) { echo("<span class='online'>Online</span>"); } else { echo("<span class='offline'>Offline</span>"); } ?>

Method #3


<?php function Visit($url){ $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init(); curl_setopt ($ch, CURLOPT_URL,$url ); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch,CURLOPT_VERBOSE,false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch,CURLOPT_SSLVERSION,3); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE); $page=curl_exec($ch); //echo curl_error($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300) return true; else return false; } if (Visit("http://www.google.com")) echo "Website OK"."n"; else echo "Website DOWN"; ?>