If you want to display a list of posts, including the thumbnail, there may be a conflict as I experienced, so instead of like “Notice: Trying to get property ‘ID’ of non-object in /wp-includes/post-thumbnail-template.php on line 101″. The reason is often caused by the existence of a particular plugin.
In these circumstances, you can create your own page where you can enter the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $ctg_art = get_posts('cat=80&numberposts=5'); FOREACH ($ctg_art as $post) { setup_postdata($post);?> <table style="margin:0;padding:0px;"> <tr> <td style="width:90px; vertical-align: top;margin:0;padding:0"> <a href="<?php the_permalink() ?>" ><?php the_post_thumbnail('thumbnail'); ?></a> </td> <td style="vertical-align: top;margin:0;padding:0px"> <span class="" ><?php the_time( get_option( 'date_format' ) ); ?> <i class="fa fa-arrow-circle-down"></i> </span> <br><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a> </td> </tr> </table><?php } ?> |
Of course, the value of expression cat=80 can be set for the target category. Also, if instead of numberposts=5 (as in the picture) is chosen, for example, the value of -1 instead of five articles will show all posts. In the shown example, I intend to create a table of posts, with the first column containing the thumbnail, and the publication date and title will be displayed in the second column. Obviously, if we wanted to, we could also invoke the excerpt.
Another option is the following, inserted into a page template.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category_name' => 'utilitati', 'posts_per_page' => -1, ); $rez_posts = new WP_Query( $args ); IF ( $rez_posts->have_posts() ) { ?> <h1>Articole din categoria UTILITĂŢI</h1><?php WHILE ( $rez_posts->have_posts() ) { $rez_posts->the_post(); ?> <ul> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> </ul><?php } }?> |
Source: ArtisansWeb
It is also interesting the article on WPbeginner.com regarding creating a shortcode to display the content of a specific category