[Support request] How do I only show 1 blog post on the home page?

Home Forums Support [Support request] How do I only show 1 blog post on the home page?

Home Forums Support How do I only show 1 blog post on the home page?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #755936
    Chris

    Right now I have infinite scroll that shows all my blog posts.

    My settings–>reading is set to 1 post to display. The home page displays all of my posts

    How do I only show 1 blog post on the home page?

    Second I want to have buttons at the bottom of my posts like Seth Godin’s Blog Page. How do I create code to do that?

    https://seths.blog/2018/06/the-two-simple-secrets-to-good-ideas/

    #756014
    Leo
    Staff
    Customer Support

    Hi there,

    Sorry I’m not sure if I understand.

    If you only want to show 1 post at the time, why would you need to use infinite scroll?

    As for buttons, are you just referring to the style or you want the Next and Back text instead of the default post titles?

    Let me know ๐Ÿ™‚

    #756105
    Chris

    Ok turns out I do need infinite scroll Seth’s home page has infinite posts.

    For my blog posts…How do I get buttons like this? at the bottom of a blog post page?

    https://drive.google.com/file/d/1bGqQMm4I4_Alh-DFOt–caKSTNP94nYe/view?usp=sharing

    For my home page…How do I get a divider and a star count?

    https://drive.google.com/file/d/1nb4tyLdwtsofe_TilUrTY2r4CZ0X8rdu/view?usp=sharing

    #756773
    Leo
    Staff
    Customer Support

    For the buttons, can you answer my question above:

    As for buttons, are you just referring to the style or you want the Next and Back text instead of the default post titles?

    For dividers, any chance you can link me to the page in question?

    The link you provided isn’t working.

    #757204
    Chris
    #757611
    Tom
    Lead Developer
    Lead Developer

    To add the buttons, you can do something like this:

    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
        if ( ! $post ) {
            return '';
        }
      
        $next = sprintf(
            '<a class="next-post button" href="%1$s" title="%2$s">Next</a>',
            get_permalink( $post ),
            $post->post_title
        );
      
      	$currentID = get_the_ID();
      	$args = array(
    	  	'numberposts' => 1,
    	  	'order'    => 'ASC',
    	  	'orderby' => 'rand',
    	  	'post__not_in' => array( $currentID ),
    	);
      
        $random_post = get_posts( $args );
    
        $random_post = sprintf(
            '<a class="button random-post" href="%1$s" title="%2$s">Random</a>',
            get_permalink( $random_post[0]->ID ),
            get_the_title( $random_post[0]->ID )
        );
    
        return $random_post . $next;
    }, 10, 4 );
    
    add_filter( 'previous_post_link', function( $output, $format, $link, $post ) {
        if ( ! $post ) {
            return '';
        }
      
        $prev = sprintf(
            '<a class="button previous-post" href="%1$s" title="%2$s">Previous</a>',
            get_permalink( $post ),
            $post->post_title
        );
    
        return $prev;
    }, 10, 4 );

    Then you’ll need to style them however you need.

    Let me know if that does it or not ๐Ÿ™‚

    #757948
    Chris

    Do I put this in the editor single post php? or somewhere else?

    #758264
    Leo
    Staff
    Customer Support

    One of these methods:

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #758684
    Chris

    ok I did code snippets. I don’t see any change even after clearing website cache

    #759244
    Tom
    Lead Developer
    Lead Developer

    Make sure post navigation is turned on in Customize > Layout > Blog.

    #759648
    Chris

    Didn’t work

    I went to layout > blog > turned on all the options

    cleared my cache and nothing happened

    I have this as my code in snippets to run everywhere

    add_filter( ‘next_post_link’, function( $output, $format, $link, $post ) {
    if ( ! $post ) {
    return ”;
    }

    $next = sprintf(
    Next‘,
    get_permalink( $post ),
    $post->post_title
    );

    $currentID = get_the_ID();
    $args = array(
    ‘numberposts’ => 1,
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘rand’,
    ‘post__not_in’ => array( $currentID ),
    );

    $random_post = get_posts( $args );

    $random_post = sprintf(
    Random‘,
    get_permalink( $random_post[0]->ID ),
    get_the_title( $random_post[0]->ID )
    );

    return $random_post . $next;
    }, 10, 4 );

    add_filter( ‘previous_post_link’, function( $output, $format, $link, $post ) {
    if ( ! $post ) {
    return ”;
    }

    $prev = sprintf(
    Previous‘,
    get_permalink( $post ),
    $post->post_title
    );

    return $prev;
    }, 10, 4 );

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