- This topic has 9 replies, 2 voices, and was last updated 1 year, 5 months ago by
Fernando.
-
AuthorPosts
-
June 30, 2022 at 9:58 pm #2269860
iamarghya
So, on this website in this latest job section see there is the last date post meta with the post title, and in the 2nd link you can see I created the same post-title concept and also I have the needed post-meta but how can I add the post meta with the post title just like the 1st website shows…
June 30, 2022 at 10:19 pm #2269875Fernando Customer Support
You can add it through a Headline Block. Headline Blocks can retrieve Post meta.
If however you want them appear as one link, you would need custom code for that.
For instance, it’s doable if you add
my-title
to the Class list of the Headline Block as such: https://share.getcloudapp.com/8Lu0pZd0, then add a snippet like this:add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-title' ) !== false ) { $my_meta = get_post_meta(get_the_ID(),'meta-date'); if($my_meta) { return $content . " " . $my_meta[0]; } else { return $content; } } return $content; }, 10, 3);
You would need to replace
meta-date
with the meta field name of your date. Then, depending if the return value of your post meta is an array or a string, you might also need to modify this part of the code:$my_meta[0]
Hope this helps!
June 30, 2022 at 10:27 pm #2269880iamarghya
Perfectly perfect now If I just want to style that date like giving a red background how can I select that date? to use in CSS?
June 30, 2022 at 10:49 pm #2269894Fernando Customer Support
Yes, you can use CSS, but we’ll need to add a class to the post meta.
You can modify the PHP snippet into something like this:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-title' ) !== false ) { $my_meta = get_post_meta(get_the_ID(),'meta-date'); if($my_meta) { return $content . ' <span class="my-meta">' . $my_meta[0] . '</span>'; } else { return $content; } } return $content; }, 10, 3);
Then, add this CSS:
span.my-meta { background-color: #ff0000; }
Hope this helps!
June 30, 2022 at 10:52 pm #2269900iamarghya
oh ok got it
June 30, 2022 at 10:55 pm #2269905Fernando Customer Support
Have you modified the PHP? Viewing the site from my end, it seems the span element hasn’t been added yet which is why the CSS isn’t working.
Kindly let us know.
June 30, 2022 at 11:01 pm #2269909iamarghya
No No, I didn’t do it at the first then I did it only. One last question, as u can see every post title has a border-bottom what CSS do I need to write for the last child having no border-bottom only the last post will have no border-bottom I tried with last-child but couldn’t work out with it so at last, I asked…😅
June 30, 2022 at 11:17 pm #2269915Fernando Customer Support
I see.
Here’s a CSS you can try:
.gb-container.cards > .gb-inside-container > .gb-grid-wrapper > .gb-grid-column:last-of-type > .gb-container { border:none; }
July 1, 2022 at 12:45 am #2269969iamarghya
Yep, perfect thanks.
July 1, 2022 at 12:48 am #2269970Fernando Customer Support
You’re welcome iamarghya!
-
AuthorPosts
- You must be logged in to reply to this topic.