<?php
add_filter( 'wp_title', 'filter_wp_title', 10, 2 );
function filter_wp_title( $title, $separator ){
$title ="New Title";
}
?>
Monthly Archives: April 2011
Template Redirection – WordPress
add_action('template_redirect','theme_function'); function theme_function(){ if(isset($_GET['sports']) { include(TEMPLATEPATH."/sports.php"); exit(); }}
Category url from its ID – WordPress
<?php echo get_category_link(categoryID); //Category URL ?>
Permalink from post id – Wordpres
<?php echo get_permalink(postId) ; // will return the permalink ?>
Plugin that allows php codes in post/page – WordPress
“Exec-PHP” plugin allows us to add php codes in posts/pages
How to check home page or not + wordpress
if (is_page('home')
echo "Home page";
else
echo "No";
How to Create Sitemap – WordPress
Use the plugin Google XML Sitemaps for XML sitemap .
Use the plugin HTML Page Sitemap for HTML sitemap .
How to display specific posts – WordPress
<?php
$thePostIdArray = array("28","74", "82", "92"); // Post IDS
$limit = 4 if (have_posts()) :
while (have_posts()) :
the_post();
$counter++;
if ( $counter < $limit + 1 ):
$post_id = $thePostIdArray[$counter-1]; $queried_post = get_post($post_id);
echo $queried_post->post_title;
endif;
endwhile;
endif;
?>
PHP script to download the PDF file
<?php
$file = 'testFile.pdf'; // file to be downloaded
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); header("Content-type: application/pdf");
header('Content-length: '.filesize($file));
header('Content-disposition: attachment; filename='.basename($file));
readfile($file);
exit;
?>
Create and download excel file – PHP
<?php
$file = 'excelFile-'.date("Y-M-D")."-".time().'.xls';
ob_start();
echo '<table border="1"> ';
echo '<tr><th>Product Name </th><th>Category</th><th>Active</th></tr>';
for ($i=0; $i<=10; $i++) {
echo "<tr><td>Product$i</td><td align='center'>Category $i</td><td>Active</td></tr>";
}
echo '</table>';
$content = ob_get_contents();
ob_end_clean();
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); header("Content-type: application/vnd.ms-excel;charset:UTF-8");
header('Content-length: '.strlen($content));
header('Content-disposition: attachment; filename='.basename($file));
echo $content;
exit;
?>