Support » Requests and Feedback » Display Custom Fields posts on static page

  • Digitalminds

    (@digitalminds)


    I’m using the code below to display the titles of the last 8 posts on a static page:

    <?php
    # Here starts Mini Loop trick: You can use this code, but _at your own risk_
    # If you want to improve this code, you’re welcome 😉
    $how_many=8; //How many posts do you want to show
    ?>
    <ul id=”news”>
    <?php
    $news=$wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts
    WHERE post_type=\”post\” AND post_status= \”publish\” ORDER BY post_date DESC LIMIT $how_many”);
    foreach($news as $np){
    printf (”

  • %s
  • “, $np->ID,$np->post_title);
    }
    ?>

    Now I want also to show the value of a custom field after the title, does anyone know how to realize this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • MichaelH

    (@michaelh)

    You’ll want to use something like get_post_custom but review Using_Custom_Fields for a discussion of the topic.

    Also might direct you to other possible choices on presenting posts:
    http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/
    http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

    Digitalminds

    (@digitalminds)

    Sorry Michael but I don’t see the connection between my problem and your links. I’ve already the titles of the posts now I also want to display the value of a custom field but it doesn’t work with the examples mentioned in the codex using_custom_fields

    MichaelH

    (@michaelh)

    Please place the code you did use in a pastebin and report the link back here. Thanks.

    Digitalminds

    (@digitalminds)

    <?php
      # Here starts Mini Loop trick: You can use this code, but _at your own risk_
      # If you want to improve this code, you're welcome ;)
      $how_many=8; //How many posts do you want to show
    ?>
    <ul id="news">
    <?php
      $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
        WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>= \"publish\" ORDER BY <code>post_date</code> DESC LIMIT $how_many");
      foreach($news as $np){
        printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
      }
    ?>
    MichaelH

    (@michaelh)

    but it doesn’t work with the examples mentioned in the codex using_custom_fields

    An example of the code you used, that didn’t work, please.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display Custom Fields posts on static page’ is closed to new replies.