WordPress.org

Forums

Displaying post title in template (2 posts)

  1. oneupdzn
    Member
    Posted 3 years ago #

    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);
  2. deepbevel
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic