Wordpress: Get post date on Category page - wordpress

On Category page displaying post of particular category with title and post date. The issue is that it is getting the date for only the first list item while for the other list item it returns blank.
Here's my code:
<div class="post-date">
<?php the_date(); ?>
</div>
How can i display post published date with each post title?

Use this
<?php the_time('F j, Y \a\t g:i a'); ?> or
<?php the_time(get_option('date_format')); ?>
When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() with a date-specific format string.

you may try the follow to get the post date
<?php the_time( get_option( 'date_format' ) ); ?>

Related

Categories with post from child categories on front page

I am developing my first WordPress site and I am using the Customizr theme. I need to build a front page, that shows the latest posts from 2 categories - News and Events and all their child categories. So my category tree looks like this:
Articles
-News
--First news child category
--Second news child category
-Events
--First events child category
--Second events child category
and I want the front page to show the category News and the category Events with all the posts in their child categories packed in 2 containers with the headlines News and Events respectively. I am a total newbie in WordPress and I've searched for days for a solution, but I think I'm searching with the wrong keywords, because I didn't found what I need. I've created a child theme, and I'm currently trying to make an index.php with The Loop to achieve that. I've also tried making a static front page which uses a different template.
So which is the right way to do that? Can you please at least give me some pointers? Thank you!
If i understood corectly you can achieve expected result with Category Parameters for WP Query. Then you can loop over posts like this:
<?php
$the_query = new WP_Query( "category_name=news,events"); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Also, to customize your front page better make a new template (home.php), do your job there and then asssign it to an empty page and make that page your front page from Settings->Reading

Reduce number of posts depending on post content

In a custom post archive; Is it possible to reduce the the number of posts shown, depending on the contents of the showing posts?
I have a custom post type for products. In the product archive there are 20 products showing on each page, 4 rows, 5 cols.
In some cases where the product image is super wide I'd like that product to be shown with double width.
When showing a super wide product, I'd like to reduce the number of posts to 19 (18 if there are two super wide products). Keeping the bottom line straight.
This is the loop for my custom post archive.
I got your point with numcols. And as you say, I should probably modify the query, making sure that page 2 and 3 (and on) shows the right posts.
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>" class="produkt_item normal various" data-fancybox-type="iframe">
<?php if ( has_post_thumbnail() ) { ?>
<div class="utvaldbild">
<?php the_post_thumbnail('produktbild'); ?>
</div>
<?php } ?>
<h2><?php the_title();?></h2>
<p><?php the_field('produktnotis'); ?></p>
<?php if (get_field('nedladdning')) { ?><div class="nedladdning"></div><?php } ?>
</a>
<?php endwhile; ?>
you could add a custom field to your post custom posttype called numcols or something like that. normal products would be 1 and super images 2 etc.
then just keep a count of them in your php code and cut off when appropriate.
you could probably modify the query in the lookup page to do this but I'd have to see some code to be of any help. ideally your custom product archive page and the definition of your custom post type.

WORDPRESS: How to remove certain content on single post page of post_format gallery?

First off I created my own theme from scratch. I've been trying to figure this out all day yesterday. Ended up using a couple of twentyelevens and twentyten's files just to accomplish this. Then deleted them cause there was no success. All I want to do is remove certain text such as "Filed Under" and "Posted By" that appears at the bottom of my single posts page. I want the Standard Single Posts Page to have the Meta Data, while the Gallery Single Posts Page doesn't have Meta Data.
I tried to use the loop.php, loop-single.php, loop-gallery.php, content.php method but nothing was working for me. Where can I start to get these two different post formats to display differently on their single pages?
Is there anything I need to add to my functions.php file just to make this work?
Do I need to recreate the loop files?
Please help...
If 'gallery' is a category, you could edit your single.php template and use is_category():
<?php if ( in_category('gallery') ) : ?>
<!-- Single post style for gallery posts -->
<?php else: ?>
<!-- Normal single post style -->
<?php endif; ?>
If it's a custom post type, you could use get_post_type() in single.php and use its result in a condition, e.g.
<?php
$post_type = get_post_type( $post->ID );
if ( $post_type == 'gallery' ): ?>
<!-- Single post style for gallery posts -->
<?php else: ?>
<!-- Normal single post style -->
<?php endif; ?>
If it's a post format, use get_post_format(), e.g.
<?php
$post_format = get_post_format( $post->ID );
if ( $post_format == 'gallery' ): ?>
<!-- Single post style for gallery posts -->
<?php else: ?>
<!-- Normal single post style -->
<?php endif; ?>

WordPress Get all the Category's Post

I have Developed WordPress Site Successfully, but i have doubt in Getting all the post by
Categories.
My Code is like this
new WP_Query("cat=54,71,72&order=ASC");
Default it is getting the first category id and the Post.
Thanks
If you want to get ALL your categories instead of a selected few, you don't need to query by category.
new WP_Query("order=ASC");
If you want to query a particular category, but you're not sure what's the category ID number, query it by category slug
new WP_Query("category_name=your-category-slug&order=ASC");
You can also use this code as well, just need to change the number of post, like as of now, below listed code is use for display 5 post only, so you have to change this limit.
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><?php the_title(); ?></li>
<?php the_content();?>
<?php endwhile;?>
</ul>

how to change for the format for the blog archives?

Now the wordpress is displaying the blog archives as following
Janauary 2012
But I want this
Jan (2)
where 2 is the total number of posts in the month of January.
How will I do this?
You have to modify the template and replace this <?php the_time('F Y'); ?> with this <?php the_time('M'); ?> (<?php $current_month = date('m'); $count = get_posts("monthnum=$current_month" ); echo count($count); ?>) and it should work.
WordPress links to archives using the "m" argument to index.php with the year first and the month second. So, for example, January 2012 would be index.php?m=201201. So, to link this, we need to create the link like this:
...

Resources