I want to create an archive page that display’s the posts in this order:
post_title | post_date | post_category
Offcourse this should be clickable that links to the post or if you click on a category than it should link to a category
What do I have so far:
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link naar <?php the_title_attribute(); ?>"><?php the_title(); ?></a> | <?php the_date();?> | <?php get_the_category;?></h2>
<?php
}
}
?>
I know that “the_permalink()” gives me the link to post and “the_title” gives me the title.
This code only shows the last 10 posts instead of the 3000.
Another problem is that the date only shows up on 2 of the 10 posts.
The category just doesn’t show up at all.
This is the first time i’m trying to really work with wordpress and perhaps i’m really doing it the wrong way so I hope you all can help me out. Thank in advance.
That’s normal WordPress behaviour. By default if you don’t specify
posts_per_page
ornumberposts
parameters toget_posts
it will use the value set in Settings > Reading. So change your args to this (-1
means it will display all your posts – change it to 3000 if you actually need it to be 3000):That, oddly, is too a default WordPress behaviour (in my opinion a bit confusing). If you look at the special note on
the_date
documentation page, it tells you that:If you want to get over this and display the date for all posts, you need to use
get_the_date
(it return the date so you’ll need toecho
it).You’re miss-using
get_the_category
– it returns an array of categories objects associated to the post and doesn’techo
anything. To display the link to the current post category, you need to use a combination ofget_the_category
andget_category_link
:You can control number of posts (say 50) like so:
For date and categories to show up Use this:
Hope that helps. If not feel free to ask!