Get Post Slug in WordPress

7

By : Josh Stauffer

I needed to get just the post slug for a project I have been working on. I found several sites that had similar ways of getting the post slug but I came up with an approach that utilizes WordPress’ get_permalink() and PHP’s basename().

The common approach:


$post_obj = $wp_query->get_queried_object();
$post_ID = $post_obj->ID;
$post_title = $post_obj->post_title;
$post_slug = $post_obj->post_name;

My approach:


$slug = basename(get_permalink());

My Favorite WordPress Plugins

0

By : Josh Stauffer
  • Subscribe to Comments – http://wordpress.org/extend/plugins/subscribe-to-comments/
  • WP-PageNavi – http://wordpress.org/extend/plugins/wp-pagenavi/
  • WP-DB-Backup – http://wordpress.org/extend/plugins/wp-db-backup/
  • Google XML Sitemaps – http://wordpress.org/extend/plugins/google-sitemap-generator/

I Created a WordPress Theme

2

By : Josh Stauffer

JOSH v1I know you are thinking… you did what? But it’s true. I have reached a milestone in my life. I just created my first ever WordPress theme. I am also very pleased with how it turned out. It took me about 8 hours to complete but most of that time was spent waiting on the trial version of Photoshop CS3 to download and fixing an annoying CSS issue. I am sure there will be some bugs that I need to fix but so far, so good.

I would like to thank Small Potato for his very basic tutorial titled “So you want to create WordPress themes huh?” If you are new to WordPress or just want a fresh, clear view of stepping through a theme then I suggest you start with his tutorial.

I would also like to thank Photoshop CS3 for making my first theme beautiful. I couldn’t have done it without you. Wink.

Next on the agenda:

  1. Validatation of XHTML & CSS
  2. Checking design in different browsers with help from IE NetRenderer
  3. Finding and fixing any bugs

Display the Latest Posts with WordPress

18

By : Josh Stauffer

If you set a static page as your front page, it can be a little tricky figuring out how to link to a page that shows your latest posts. So far I have come across two solutions you can use with your WordPress blog when linking to such a page.

Solution One

Create a link in your sidebar or somewhere on your site that looks like this: http://www.yourdomain.com/?p=all You should replace the http://www.yourdomain.com/ with the location of your blog.

Solution Two

You need to create a new page template by copying an existing one. In your new page template, find this line:

<?php while (have_posts()) : the_post(); ?>

Then replace that line with this code:

<?php $my_query = new WP_Query('showposts=10');

while ($my_query->have_posts()) : $my_query->the_post();

$do_not_duplicate = $post->ID; ?>

The code you just added creates a loop and retrieves the latest 10 posts and will display them on a page you create with your new template.

If you know of another solution to accomplish this task, please share it with my readers and me by commenting below.