WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To Create Dynamic Table Listing Posts and Using Custom Fields??? (8 posts)

  1. raynerlim36
    Member
    Posted 4 years ago #

    Hi!

    I'm sorry that the title may be a little misleading, but I tried to keep it "brief and descriptive".
    Also, I don't mean to be rude here but I am in a big hurry so I am hoping people will respond fast.

    Okay, I'll be straight to the point now:

    I need to have a table with the headers "Title", "Author", "Class", "Year". I want the table to add a row for every post from a certain category, with the title of the post in the "Title" field, and the "Author", "Class" and "Year" fields being populated with information from that post's custom fields/metadata.

    Secondarily and not so importantly, I need the table to have alternate row colours and must be sortable.

    Maybe you could recommend me a suitable plugin (I haven't found any to be suitable) or give me the code and instructions. Please, no telling me to write code myself as I can't!

    Thanks a lot for any help you are going to give me!

    Rayner

  2. MichaelH
    Member
    Posted 4 years ago #

  3. raynerlim36
    Member
    Posted 4 years ago #

    Sorry MichaelH, but how do I make use of the plug-in to generate a table? Sorry but I really need tutorials to teach me how to do it as I'm not a coder.

    What I need is like WP-Table Reloaded but is dynamically loaded and not a static table. I guess it may be hard, that's why I'm asking for help here. Thanks.

  4. MichaelH
    Member
    Posted 4 years ago #

    Since you didn't want to do any coding, I linked to some plugins that will display posts without having to code templates.

    You may consider revising your requirements.

  5. raynerlim36
    Member
    Posted 4 years ago #

    Thank you for your help, MichaelH.

    I'm sorry but I really need the dynamic table.
    Maybe I can cut down my requirements a bit, so is there a plug-in that can list posts from a certain category in a tabular format (does not need to be from WordPress.org; I don't know how to search for it)?
    I just need some sample code (if that is possible) as to how to add a row for every post with "Title" for the table header, then maybe I can slowly build up from that foundation? Just really, really need a table that displays pots, no matter how simple it is.

    Also on a side note, I'm actually using BuddyPress and a Buddypress theme, so should I post here or in the BuddyPress forums?

    Thanks!

  6. MichaelH
    Member
    Posted 4 years ago #

    Display 5 posts with two custom fields called "class" and "year" in a table.

    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 5,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {  ?>
     	<TABLE border="1" summary="This is a table with no class">
      <CAPTION><EM>A table with no class </EM></CAPTION>
      <TR><TH>Post<TH>Author<TH>Class<TH>Year
      <?php
      while ($my_query->have_posts()) : $my_query->the_post();
        $class = get_post_meta($post->ID, 'class', true);
        $year = get_post_meta($post->ID, 'year', true); ?>
        <tr><th><?php the_title(); ?><td><?php the_author(); ?><td><?php echo $class; ?><td><?php echo $year; ?>
      <?php endwhile; ?>
      </TABLE>
    <?php }
    wp_reset_query();
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  7. raynerlim36
    Member
    Posted 4 years ago #

    Thanks very much! Worked like a charm.
    Changed topic status to resolved.

  8. MichaelH
    Member
    Posted 4 years ago #

    I'll mark as resolved but you can do that over there --->

Topic Closed

This topic has been closed to new replies.

About this Topic