[Resolved] How to add custom fields (meta data) to posts on home page and archive pages?

Home Forums Support [Resolved] How to add custom fields (meta data) to posts on home page and archive pages?

Home Forums Support How to add custom fields (meta data) to posts on home page and archive pages?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #454963
    sampath

    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

    #454983
    Tom
    Lead Developer
    Lead Developer

    You 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 πŸ™‚

    #454993
    sampath

    hey 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???

    #455332
    Tom
    Lead Developer
    Lead Developer

    You shouldn’t need to override anything – you can just create your own fresh function and insert it into that hook.

    #455390
    sampath

    Yeah, 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.

    #455601
    sampath

    changing the div class name from entry-meta to someother class worked.

    Thanks

    #455630
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working! You can also just override that display: none CSS to display: block with an !important or a more specific selector πŸ™‚

    #455643
    sampath

    okay 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
    Thanks

    #455822
    Leo
    Staff
    Customer Support

    You would just add .home at the start of the selector.

    For example, .inside-article would be .home .inside-article

    #455910
    sampath

    i 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’?

    #455916
    sampath

    this 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

    #456076
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working πŸ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.