Home › Forums › Support › How to add custom fields (meta data) to posts on home page and archive pages?
- This topic has 11 replies, 3 voices, and was last updated 6 years, 4 months ago by Tom.
-
AuthorPosts
-
December 21, 2017 at 9:27 pm #454963sampath
Hey, I am new to wordpress(php) development. I have purchased generatepress plugin recently. I was able to modify single posts page successfully to my requirement.
1. I have some meta data as custom fields for each post, I am trying to add this meta data to the posts on the home page instead of date, author, category meta data.
2. I also want to style or change the post format to my requirement. Does changing css will be enough and right way to do it?>
I am not able to find the right place to add it. look like post-meta.php is the right place but i need more help: whats the right way to add and where ?
Thanks in advance
December 21, 2017 at 10:22 pm #454983TomLead DeveloperLead DeveloperYou can use this hook to add your custom PHP into the meta area: https://docs.generatepress.com/article/generate_after_entry_title/
As for the post format, the
<article>
element has the post format as a class which you can use to apply your CSS.Let me know if you need more info π
December 21, 2017 at 11:23 pm #454993sampathhey thanks, overriding generate_post_meta function to add custom meta data to posts on homepage worked, but as soon as i enabled ‘blog’ from the GP plugin my changes are gone???
December 22, 2017 at 9:36 am #455332TomLead DeveloperLead DeveloperYou shouldn’t need to override anything – you can just create your own fresh function and insert it into that hook.
December 22, 2017 at 11:17 am #455390sampathYeah, adding a new function to the hook works too!
Also, i found out why my meta data is not showing when i enable ‘blog’, its because i have unchecked ‘display post data, author, categories, tags’ and its hiding my custom meta data too with a css style – display: none.How do I show my custom meta with the ‘blog’ activated from the GP Plugin.
I really appreciate your support Tom.
December 22, 2017 at 6:59 pm #455601sampathchanging the div class name from entry-meta to someother class worked.
Thanks
December 22, 2017 at 10:55 pm #455630TomLead DeveloperLead DeveloperGlad you got it working! You can also just override that
display: none
CSS todisplay: block
with an !important or a more specific selector πDecember 22, 2017 at 11:20 pm #455643sampathokay thanks
When I add a css class to a div element I am seeing the same class in both homepage and single page.Is there a way to apply css class only to homepage elements??
I was modifying ‘generate_post_classes’ and ‘generate_main_classes’ functions
ThanksDecember 23, 2017 at 8:00 am #455822LeoStaffCustomer SupportYou would just add
.home
at the start of the selector.For example,
.inside-article
would be.home .inside-article
December 23, 2017 at 11:23 am #455910sampathi am trying to add bootstrap column class to article element i.e ‘col-lg-4 col-sm-6 col-xs-6’ but they are being applied to both home posts and single posts page.
your solution might not be helpful in this case
edit: also i did not find any .home class already in there, did you mean to ‘add a new .home class to inside-article element and style it’?
December 23, 2017 at 11:59 am #455916sampaththis helped me to know current view page https://wordpress.stackexchange.com/questions/83887/return-current-page-type and i added classes based on the ‘current view’
edit: or just ‘is_single()’ function.
thanks
December 23, 2017 at 10:48 pm #456076TomLead DeveloperLead DeveloperGlad you got it working π
-
AuthorPosts
- You must be logged in to reply to this topic.