[wp-hackers] get_page_link by page name/slug?

Robin Adrianse shorty114 at shorty114.net
Sun Nov 26 20:33:57 GMT 2006


No, I think he's using it not in the loop for the page in question. For a
navigation, eg.

On 11/26/06, Michael B <miklb.online at gmail.com> wrote:
>
> Forgive me if I misunderstand, but is the_permalink exactly what you want?
> http://codex.wordpress.org/Template_Tags/the_permalink
>
> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
>
>
> ~miklb
>
>
>
> On 11/26/06, Lee Kelleher <leekelleher at gmail.com> wrote:
> >
> > Does anyone know if there is a way in the existing WP core code to get
> the
> > hyperlink to a page by it's slug/name?
> >
> > The reason for asking is that when I develop/maintain a WP theme, the
> > post/page IDs are completely out-of-step with the production site, and
> > using
> > the get_page_link() function only allows for the ID (integer).  So it
> > would
> > be nice to use the page slug/name as this would work seamlessly across
> > both
> > dev and production environments.
> >
> > I have written some code to do this...
> >
> > function get_page_link_by_slug($page_slug) {
> > >     global $wpdb;
> > >     $page_id = 0;
> > >     $results = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE
> > > post_status = 'static' AND post_name = '$page_slug'");
> > >     if ($results) {
> > >         foreach ($results as $result) {
> > >             $page_id = $result->ID;
> > >         }
> > >     }
> > >     return get_page_link($page_id);
> >
> > }
> > > usage: echo get_page_link_by_slug('about');
> > >
> >
> > I based the syntax on the get_linkobjectsbyname() function - which adds
> > another hit on the database, but it saves duplicating the code that
> > formats
> > the hyperlink.
> >
> > Would this be useful in the core code? or does anyone know of a better
> way
> > of achieving this?
> >
> > Cheers,
> > - Lee
> >
> > --
> > Lee Kelleher
> > http://leekelleher.com/
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list