$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged='.$paged);
paged query in wordpress
contact form 7 controlling br tags
Have you encountered br tags messing your contact form 7 forms. you can remove it using below code in wp-config.php:
define( 'WPCF7_AUTOP', false );
more info at http://contactform7.com/controlling-behavior-by-setting-constants/
Posting to a wordpress page from a form
Ever tried to post a form to wordpress page? sometimes you might have encountered 404 error. this is due to reserved name for worpress like “name”. You should not have input with name “name” or else you will get 404 error after submission.
for more details go to : http://www.cabeeb.com/2009/09/posting-a-form-to-a-wordpress-page/
Get top parent page id in wordpress.
<?php
function getTopParentPageId($page_id){
$mypage = get_page($page_id);
if ($mypage->post_parent == 0){
return $mypage->ID;
}
else{
return getTopParentPageId($mypage->post_parent);
}
}
?>
SEO friendly timthumb on wordpress
Many of you love using timthumb in your wordpress theme but don’t use it because it does not generates seo friendly urls for images. I was asked by a client to make timthumb urls seo friendly and here is how I did that.
First open your wordpress site .htaccess file. Generally it is located in root of your wordpress installation.
It should look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Now create new folder in your root call it let’s say images and place cache folder and timthumb in there then edit your .htaccess file as below
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(images) [NC]
RewriteRule . /index.php [L]
RewriteRule ^images/(.*)x(.*)/r/(.*) images/timthumb.php?src=http://example.com/$3&w=$1&h=$2&zc=1&q=100&a=tl
</IfModule>
# END WordPress
Replace example.com with you site name:
Now upload htaccess file and where you need to use timthumb do as below
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a href="'.get_permalink().'"><img src="'.get_bloginfo('url').'/images/715x440/r/'.str_replace(array('http://example.com/', 'http://www.example.com/'), array('',''), $thumbnail[0]).'" width="715" height="440" alt="'.get_the_title().'" /></a>';
endif;
?>
That should do the trick for making timthumb url seo friendly.
Getting post thumbnail
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a href="'.get_permalink().'"><img src="'.get_bloginfo('template_url').'/timthumb.php? src='.$thumbnail[0].'&amp;w=715&amp;zc=1&amp;q=95&a=tl" width="715" alt="'.get_the_title().'" /></a>';
endif;
?>
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
?>
<a href="<?php echo $thumbnail[0];?>" class="modal"><img src="<?php bloginfo('template_url');?>/timthumb.php?src=<?php echo $thumbnail[0];?>&w=218&h=135&zc=1&q=95&a=tl" class="frame_img" /></a>
<?php endif;?>