Connect with me

Latest Tweets

WordPress Permalink Without Using GUID

Posted on by admin


Sometimes we have a need of pretty link instead of default link ….

Default link is http://mavendeveloper.com/?p=3

pretty link is http://mavendeveloper.com/2010/08/sub-domain-not-working-in-wordpress-3-0-or-wpmu/

if you are in loop the below code works well:

get_permalink($post->ID);

but sometimes getting pretty link is impossible when you have to construct pretty link outside of loop in custom requirement… in such a situation what can be done is … query the database and generate you own pretty link like shown below :

SELECT CONCAT(DATE_FORMAT(post_date,’%Y/%m/%d/’),post_name) AS permalink FROM wp_posts WHERE post_status=’publish’;

I will show you the complete example how to use this from which you will have clear idea :

example:

$sql_query = "select *,CONCAT(DATE_FORMAT(post_date,'%Y/%m/%d/'),post_name) AS permalink from ".$blogPostsTable." where post_status = 'publish' and post_type = 'post'
order by post_date desc limit 0,5";
$sql = mysql_query($sql_query);

while($array = mysql_fetch_assoc($sql)){

$recent_post3 .= ” “;

$recent_post3 .= ‘ ‘.substr($array['post_title'],0,45). ‘..‘;

$recent_post3 .= ” “;

}
echo $recent_post3;

Cheers

Share
[del.icio.us] [Digg] [dzone] [Facebook] [Friendsite] [Google] [LinkedIn] [MySpace] [Twitter] [Windows Live] [Yahoo!] [Email]

      


Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


What is difference between managed and backing beans?

Although general convention is to use one Managed beans per JSF page/fragment, but managed beans can be used with multiple pages.  But Backing Bean can be only used for single page/fragment. Normally, Managed Bean is desired to have Pageflow scope, … Continue reading