WP Posts (Date Format & Comments Number)

Hi guys,
I’m not quite sure if this is HTML/CSS related question, but I’ll try to post it here.

So, what I want to do?
I would like to change the Date format for my WP posts.
I already tried to change the Date format under WP Dashboard Settings, but that didn’t work for Posts (only for Comments).

The second thing I would like to do is to put the Total number of comments for each post right next to Date field.
I tried to modify that settings with my Theme editor, but the only thing I can do is to Hide/Show Date and Author.

Any advice on how can I do that?

My website: www.supertata.net
My SS: https://drive.google.com/file/d/0B8mgV8g928bRN1VWSmwxcXZLU2M/view?usp=drivesdk

Thanks

Hi @Marin. You are using the theme Kotha. Do you have a child theme set up? The reason I asked is that if you make any changes to the code for this theme, they will be wiped out the next time you install an update for that theme. To do what you want to do, you really should make the changes in a child theme (https://codex.wordpress.org/Child_Themes).

It would probably be better if your question were moved to the WordPress forum. You may get a better response there.

Hi.
I don’t have a child theme set up.
But, I use Custom CSS plugin which allows me to override every style from the original CSS file.
So, I’m not worried about that.
I can modify whatever I want with Custom CSS plugin.
My only problem is that I don’t know how to do that changes? :slight_smile:

The trouble is that you don’t have the number of comments displayed with the posts at all, so it might necessitate adding or moving some PHP code, not adjusting your CSS. Do you have any option in your theme editor that pertains to number of comments?

Yes, CSS can basically only style whats there, and it can’t format dates.

Can you find which file in the theme is creating this HTML ?

<div class="entry-meta">
                            <ul class="list-inline">
			                <li>
                    <span class="posted-on">ruj. 29, 2016</span>
                </li>
                <li>/</li>
            </ul>
                    </div>

@Mittineague
Which file in the theme is creating that HTML?
Where can I find that?

@WebMachine
No, I have no options in my theme editor that pertains to number of comments.
However, I installed a Comments plugin that allows me to show Number of comments right above the “Leave a Reply” section. But, you have to open a specific post (you can’t see that on Home page).

As a new user I’m not able to insert more than 2 hyperlinks here, so I can’t show you what I mean. :smirk:

Theme files are typically under wp-content/themes/the-theme-mame/

If you open the files in your text editor you will hopefully be able to recognize which file is the one you’re interested in.

It will be HTML mixed with PHP so it will look different, but the tags, tag nesting and class attributes should be the same.

screen captures will work, but TBH what we need to see is the PHP code that creates the output, not a rendered page.

        <?php if ( 'post' == get_post_type() ) : ?>
            <div class="entry-meta">
                <?php kotha_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif; ?>

Maybe this one?
I found that in content-post.php
Should I upload that file here?

Then you will only be able to accomplish what you want by changing the php code in the theme (which means using a child theme). Once you have done that, we can help you with the code that you need for both the date formatting and displaying the number of comments.

That could very well be the file involved.

If you temporarily hack it to this does the text "Date: " show?

        <?php if ( 'post' == get_post_type() ) : ?>
            <div class="entry-meta"><span>Date: </span>
                <?php kotha_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif; ?>

No, it doesn’t.

Do I really have to set up a child theme?
There’s no other way to do that?

If you don’t set up a child theme, you will have to change the code in the theme itself. That leaves you with three options: either lose your changes when you install an updated version of the theme, keep track of exactly what changes you made and make those same changes each time you install an updated version of the theme, or never install an updated version of the theme ( a very, very serious security risk).

I understand.
You’re suggesting me smarter and safer choice.
But, I already made a backup on my laptop.
So, if something goes wrong I can always upload my theme files back on server with FTP.
My priority now is to fix those issues with date and comments.

I just downloaded the kotha theme and have been looking at it in my IDE.

There are two files that call the kotha_posted_on function content-single.php and content-post.php

You don’t have to. But believe me, you may not know it now, but you want to.

It shouldn’t be all that hard if you follow the steps described in the codex page WebMachine linked to in post # 2, give it a read.

Basically you’ll need to create a folder eg. kotha-child
Put your versions of the content-single and content-post files in it.
Write your equivalent of the kotha_posted_on function eg kotha_child_posted_on
Have you content-single and content-post files call your function instead of the original theme function that’ in the template-tags.php file.

That would be the same as not updating the theme. Any Security Bug fixes and Feature enhancements would not be applied.

No, it doesn’t sound hard.
You’re right - I’ll do that.:wink:

So, now when we know it’s content-single.php and content-post.php that call the kotha_posted_on function - What can we do?

After you have set up the child theme, the code to display the number of comments is as follows:

<?php if ( comments_open() )  : ?>
     <?php comments_popup_link( 'No comments', '1 comment', '% comments' ); ?>
<?php endif; ?>

Where is the function kotha_posted_on(); defined? Is it in the functions.php file?

1 Like

No, I can find it only in content-single.php and content-post.php

It depends on how you like your comments. I would do

        <?php if ( 'post' == get_post_type() ) : ?>
            <div class="entry-meta"><span>Date: </span>
                <?php // kotha_posted_on(); ?>
                <?php kotha_child_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif; ?>

and it would be enough to let me know what was going on.

But you could do something like this instead if you didn’t mind the comment being output to the HTML


        <?php if ( 'post' == get_post_type() ) : ?>
            <div class="entry-meta"><span>Date: </span>
<!-- display dates formatted the way I want them to be displayed -->
                <?php kotha_child_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif; ?>

kotha_posted_on() is defined in inc/template-tags.php.

    if (!function_exists('kotha_posted_on')) {
        function kotha_posted_on()
        {
            ?>
            <ul class="list-inline">
            <?php if (!get_theme_mod('kotha_post_author_name')): ?>
                <li>
                    <span class="author vcard">
                        <?php _e('By ', 'kotha');
                            printf('<a class="url fn n" href="%1$s">%2$s</a>',
                                esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                                esc_html(get_the_author())
                            ) ?>
                    </span>
                </li>

                <li>/</li>
            <?php endif; ?>

            <?php if (!get_theme_mod('kotha_post_date')): ?>
                <li>
                    <span class="posted-on"><?php the_time('M d, Y') ?></span>
                </li>

                <li>/</li>
            <?php endif; ?>

            <?php if (!get_theme_mod('kotha_post_cat')): ?>
                <?php if (get_the_category_list()): ?>
                    <li>
                        <span class="posted-in">
                            <?php echo get_the_category_list(_x(', ', 'Used between list items, there is a space after the comma.', 'kotha'));
                            ?>
                        </span>
                    </li>
                <?php endif; ?>
            <?php endif; ?>


            </ul>
        <?php
        }
    }

Go down to where the date is defined, and you can change its format there.

1 Like