- This topic has 11 replies, 4 voices, and was last updated 5 years, 3 months ago by
Ying.
-
AuthorPosts
-
February 9, 2021 at 9:30 am #1652041
Jatin
Hi Guys,
I want to show the comments count with hyperlink direct to comments in the header element as shown in screenshot. It should show the comments field only when the count of comment is greater than 0 that means if someone has not commented on the post then i do not want to show this field. Please advise if its possible. I am using header element. Post link in the Information box.
February 9, 2021 at 12:43 pm #1652207Leo
StaffCustomer SupportHi there,
You can create a shortcode
[comment_number]for comment and add it in the header element:add_shortcode( 'comment_number', function() { ob_start(); $comments = get_comments_number(); if ( $comments > 0 ) { comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); } return ob_get_clean(); } );Adding PHP: https://docs.generatepress.com/article/adding-php/
Hope this helps 🙂
February 9, 2021 at 6:01 pm #1652414Leo
StaffCustomer SupportI’ve updated the answer above to meet the second requirement.
February 10, 2021 at 1:08 am #1652660Jatin
Thanks Leo,
It works fine. However does not look nice. Can we have it under the last updated on with the same font size and styling and aligned.
February 10, 2021 at 9:21 am #1653374Tom
Lead DeveloperLead DeveloperRight now you have something like this:
<span class="hero-date">{{post_date}}</span>Try this:
<span class="hero-date">{{post_date}} <br /> [comment_number]</span>February 10, 2021 at 9:25 am #1653385Jatin
Hi Tom,
Currently have this: Please advise what should i change i to ?
<div class="heading-wrap"> <h1>{{post_title}}</h1> </div> <div class="hero-meta"> {{post_author}} | {{post_date}} | {{post_terms.category}} <br/> [modified_date] [comment_number] </div>February 10, 2021 at 1:06 pm #1653598Tom
Lead DeveloperLead DeveloperTry this:
<span class="hero-date">[comment_number]</span>That’ll make it inherit the styles from the date.
Then you can adjust the link color:
.hero-date a { color: #fff; }February 11, 2021 at 1:16 am #1653999Jatin
It does not look correct, please check the screenshot. It picked up Last Updated on: 13 comments also aligned to the right. When there is no comment on the post it shows as Last Updated on:
Requirement:
To be shown under the Last Updated on field e.g. like this:
Last Updated on: February 10,2021
13 Comments
February 11, 2021 at 9:52 am #1654793Jatin
Please update.
February 11, 2021 at 10:13 am #1654829Tom
Lead DeveloperLead DeveloperOk, instead of this:
[modified_date] [comment_number]
Do this:
<div class="right-side-hero-meta"> [modified_date] [comment_number] </div>Then add this CSS:
.right-side-hero-meta { margin-left: auto; font-size: 9pt; text-align: right; } .right-side-hero-meta > .hero-date { display: block; float: none; } .right-side-hero-meta a { color: #fff; }February 11, 2021 at 10:32 am #1654853Jatin
Thanks, it worked but it also messed up the padding around the existing meta.
February 11, 2021 at 11:47 am #1654936Ying
StaffCustomer SupportHi Jatin,
Try this CSS:
.page-hero .entry-date.published, .page-hero a[rel="tag"] { display: inline-table; }Let me know 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.