Black Friday Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Customising posts loop – layout and custom fields

Home Forums Support Customising posts loop – layout and custom fields

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #398096
    Pradeep

    Hello there,

    I’m building a magazine/newspaper layout site and its posts got some custom fields (for example, reading time) added to them manually. On its home page, I need to display posts under 2-3 different categories. I can live with GP’s standard column layout to display those posts but only with a couple of changes a) I need to add a couple of custom field values to posts meta b) I need to make some layout changes such as adding a horizontal lines, category specific badges etc.

    Could someone please explain which template I need to modify to make those layout changes as I couldn’t figure that out (I’ve been making static sites for way too long!)? Or is there a more efficient way to do such modifications?

    You can view a part of the wire-frame here.

    Many thanks in advance!

    GeneratePress 1.4
    GP Premium 1.4.3
    #398146
    Leo
    Staff
    Customer Support

    Hi there,

    a) Filters should be helpful for this. Here are a couple:
    https://docs.generatepress.com/article/generate_post_author_output/
    https://docs.generatepress.com/article/generate_post_date_output/

    See full list here: https://docs.generatepress.com/collection/filters/

    b) This question is a bit broad but CSS solution should do for horizontal lines at least. If you can link me to the page and let me know where you would like to add it I can help you out?

    You might be interested in GP hooks as well: https://docs.generatepress.com/article/hooks-overview/

    #398325
    Pradeep

    Leo,

    Thanks for the great tips. And I managed to get some of the work I wanted to get done by adding the following:

    add_action( 'wp', 'tu_remove_meta_on_archives' );
    function tu_remove_meta_on_archives() {
        if (is_home() || is_archive()) {
            add_filter( 'generate_post_date', '__return_false' );
            add_filter( 'generate_post_author', '__return_false' );
            add_filter( 'generate_show_categories', '__return_false' );
            add_filter( 'generate_show_tags', '__return_false' );
            add_filter( 'generate_show_comments', '__return_false' );
        }
    }
    
    add_action('generate_after_entry_header','add_post_read_time' );  
    function add_post_read_time() {  
    	if (is_home() || is_archive()) {?> 
    			<div id="after-title">
    			 <hr>
    			 <i class="fa fa-clock-o" aria-hidden="true"></i>
    			 <p class="post-read-time"><?php echo get_post_meta( get_the_ID(), 'word-count', true ); ?> Read </p>
    			</div>
    	<?php 
    	}
    }

    Next task for me is to add multiple post loops to home page. I’m still testing all these on a local servers so I am unable to give you the access to it. However I’ve added another image that should give you a better understanding of what I’m trying to do. You can find it here. Is there a “GP way” of adding multiple post loops where I can limit each of those to a single category and to a limited number of posts? Other than using one of those frequently mentioned plugins. Is there a standard post loop that I can modify and add to my home page?

    Many thanks in advance.

    #398615
    Tom
    Lead Developer
    Lead Developer

    To do that, you would need to build your own index.php file in your child theme and structure it to use multiple loops etc..

    Or you could try something like WP Show Posts, but even that would require some modifications.

    #398630
    Pradeep

    Thanks Tom! I’m OK with building my own index.php file. I was just wondering if there’s a way to GP’s posts loop to get the column layout. No worries if there isn’t a quicker way.

    #398820
    Tom
    Lead Developer
    Lead Developer
    #401071
    Pradeep

    Thanks Tom! Just one question before I close this ticket.

    When I tried to use my own index.php file I noticed that no matter what I did, GP was always using page.php as the home page template (I have set up a static home page). I tried with both index.php and home.php but none of those worked. Only when I tried with front-page.php it let me override page.php settings. I was under the impression if index.php or home.php present, they take the control over page.php when it comes to home page. Is that behaviour normal?

    And I’m taking this opportunity to thank you guys for all the amazing support you provide. I remember the days when I was using a very popular theme from the most popular theme site. It was almost impossible to get proper answers for the sorts of questions I’ve asked in here. It must be exhausting but you guys make the (WordPress) world a better place.

    Cheers

    #401085
    Tom
    Lead Developer
    Lead Developer

    I believe index.php and home.php are reserved for the page which displays posts.

    If you’re front page is a static page, then front-page.php is the way to go.

    Really glad to hear that the support has been helpful! 🙂

    #401087
    Pradeep

    That explains it. Thanks again Tom! Keep up the great work.

    #401089
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.