Display ID of post without going through the Loop
-
Hi,
I found out that function below ( single_post_title() ) can display the title without having to go through the Loop. The functions is in /wp-includes/template-functions-general.php
My question is,
Is there a way to modify the function so that it can display the content ID?
(Or is there any other alternative which can achieve similar result?)Pls help.
Thanks.
function single_post_title($prefix = ”, $display = true) {
global $wpdb;
$p = get_query_var(‘p’);
$name = get_query_var(‘name’);if ( intval($p) || ” != $name ) {
if ( !$p )
$p = $wpdb->get_var(“SELECT ID FROM $wpdb->posts WHERE post_name = ‘$name'”);
$post = & get_post($p);
$title = $post->post_title;
$title = apply_filters(‘single_post_title’, $title);
if ( $display )
echo $prefix.strip_tags($title);
else
return strip_tags($title);
}
}
- The topic ‘Display ID of post without going through the Loop’ is closed to new replies.