WordPress.org

Ready to get started?Download WordPress

Forums

the_permalink, I can't send user to the right pages! (3 posts)

  1. bndooley
    Member
    Posted 8 years ago #

    On the dashboard, when my user clicks a link under "recent posts" I want to send them directly to the post, instead of to the edit screen.

    I fiddled with the code, and it generates the titles fine, but it won't generate the correct urls.

    Here is the code.

    //<?php
    if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) :
    ?>
    <div>
    <h3><?php _e('New Posts'); ?> ">»</h3>

      <?php
      foreach ($recentposts as $post) {
      if ($post->post_title == '')
      $post->post_title = sprintf(__('Post #%s'), $post->ID);
      echo "
    • <a href='";
      the_permalink();
      echo "'>";
      the_title();
      echo '
    • ';
      }
      ?>

    </div>
    <?php endif; ?>//

    I'm trying to learn php and it's all very trial and error. Can't figure out where the mistake is! Please help!

    Best,
    Ben Dooley

  2. Austin Matzko
    Member
    Posted 8 years ago #

    Right now, the code in wp-admin/index.php for printing out the recent posts looks like this:

    foreach ($recentposts as $post) {
    if ($post->post_title == '')
    $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo "<li><a href='post.php?action=edit&amp;post=$post->ID'>";
    the_title();
    echo '</a></li>';
    }

    You might try changing it to this:

    foreach ($recentposts as $post) {
    if ($post->post_title == '')
    $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo "<li><a href='" . get_permalink($post->ID) . "'>";
    the_title();
    echo '</a></li>';
    }

  3. bndooley
    Member
    Posted 8 years ago #

    Filosofo,

    Thanks for your help. Worked like a charm. You rock.

    Best,
    Ben

Topic Closed

This topic has been closed to new replies.

About this Topic