0

The idea here is the following (I've now uploaded a picture to make it clearer what I need):

  1. Create a new page that contains a nicely formatted CSS table.
  2. Each row would refer to a specific post from a specific category.
  3. Each column would refer to specific information about that post (linked title, post date, post author, etc.)

Do I have to learn how to fetch that specific information from the database in order to populate this table? Or is there any easier way to "tell" WordPress what I need to be (dynamically) allocated to each cell?

Thanks! I'm really in the dark as to how to start this. Would appreciate any help I can get.

basic image example of what I need

  • Toscano, what you are looking to do is create a wordpress loop. A quick google search on creating one or using wp_query will get you started in the right direction. Your question is fairly vague so it's difficult to give more assistance. – rudtek Feb 24 '17 at 17:25
  • Thanks, @rudtek. I've now attached a picture that might make it clearer. Basically, I just a table that shows a list of posts from different categories, and if you want to check out a specific post, just click the link and there you'd go. No images on that page, just a quick and easy to browse text table where you can have a quick glance of everything (and then click and go there if you want to). Kind of like an index, almost. – Toscano Feb 24 '17 at 18:12
0

1: You can use Page template and custom WP_Query to show posts from a specific category into a page.

2: you can also achive same thing with shortcode where you will have to create a shortcode containing posts from specific category and paste that shortcode into your page.

Update

added sample code for custom page template and wp_query

<?php
/**
 *
 * Template Name: Custom post page
 *
 **/
get_header(); ?>

<div class="main-content" id="main">

<?php
$args = array(
  'post_type' => 'post',
  'posts_per_page'  => 10,
  'category_name' => 'your-category-slug', // replace it with your category slug
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : ?>
<table class="table post-table">
  <thead>
    <tr>
      <td><strong>Title</strong></td>
      <td><strong>Author</strong></td>
      <td><strong>Post Date</strong></td>
    </tr>
  </thead>
<?php  while( $query->have_posts() ) : $query->the_post();
?>

  <tbody>
    <tr>
      <td><?php the_title(); ?></td>
      <td><?php the_author(); ?></td>
      <td><?php the_date( 'F j Y'); ?></td>
    </tr>
  </tbody>

<?php endwhile; ?>
</table>
<?php endif; wp_reset_postdata(); ?>
</div>
<?php get_footer(); ?>

create a new php file inside your theme folder and place the above code into it. and them create a new page from WP dashboard and on the right sidebar select your Custom post page template.

|improve this answer|||||
  • Thanks, @Abdul Rehman ! Guess this is exactly what I needed. Thanks again. – Toscano Feb 24 '17 at 20:01
1
<table>
  <tr>
    <th>Category Name</th>
    <th>Post Title</th>
    <th>Author</th>
    <th>Published Date</th>
  </tr>

<?php $temp = $wp_query; $wp_query= null;
    $wp_query = new WP_Query(); $wp_query->query('showposts=10' . '&paged='.$paged);?>

    <?php if ( $wp_query->have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  <tr>
    <td><?php the_category( ', ', $parents, $post_id ); ?></td>
    <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
    <td><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"> <?php the_author(); ?> </a></td>
    <td><?php the_date(); ?></td>
  </tr>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</table>

You Can try this. Hope this will help you.

|improve this answer|||||
0
<?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        //
        // Post Content here
        //
    } // end while
} // end if
?>

inside of the while loop you will put in your html for your table and inside of the table you will need to call the_category(); the_title(); the_author(); get_the_date('j/n/y');

NOTE: Make sure your header row to your table is not inside the while loop otherwise you will spit out the header row as well.

|improve this answer|||||
  • What the above will do is loop through all your posts and spit them all out displaying only the data you are asking for. (which is category, title, author, and date. So you only need to create one row (not including your header row) and they will loop. – Landon Call Feb 24 '17 at 18:23
  • You could thumbs up my answer then. :) hope it helped. – Landon Call Feb 25 '17 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.