WordPress.org

Support

Support » How-To and Troubleshooting » Displaying post title in template

Displaying post title in template

  • I need to display all of the post on a page with the post title as the anchor. I have the following script, however, it displays the page name instead of the post name for each of the posts it loops throug.

    <?php
    /*
    Template Name: List post links
    */
    $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
    	WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    
    foreach($postID as $post_link) {
    	?>
        <?php $weburl = get_permalink($post_link);
    	$appurl = str_replace("http://laughterlounge.oneupdzn.com/", ("http://apps.facebook.com/laughterlounge/"), $weburl);
    	?>
    	<a href="<?php echo $appurl ?>" ><?php echo single_post_title(); ?> </a><br />
    
    	<?php
    }
    ?>

    This second is just to change from the hosted URL to the app URL for posting to twitter / facebook as the app url, if anyone was wondering.

    $weburl = get_permalink($post_link);
    	$appurl = str_replace("http://laughterlounge.oneupdzn.com/", ("http://apps.facebook.com/laughterlounge/"), $weburl);
Viewing 1 replies (of 1 total)
  • I’m not great with code, (especially the foreach) but you may have to include the_title as part of the output. The id alone may not get it.

Viewing 1 replies (of 1 total)
  • The topic ‘Displaying post title in template’ is closed to new replies.
Skip to toolbar