[Resolved] How to show Recent Posts and Recent Pages on homepage?

Home Forums Support [Resolved] How to show Recent Posts and Recent Pages on homepage?

Home Forums Support How to show Recent Posts and Recent Pages on homepage?

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1583427
    Vlad

    Hello!
    On my site, I use both posts and pages to add new content. But the homepage only shows Recent Posts.
    What code should I add to show Recent Posts and Recent Pages on the homepage?
    Thank you.

    #1583614
    Leo
    Staff
    Customer Support

    Hi there,

    You will need a plugin like WP Show Posts:
    https://en-ca.wordpress.org/plugins/wp-show-posts/

    Let me know if this helps 🙂

    #1583860
    Vlad

    Thanks for the answer!
    As I understand it, the plugin can display posts or pages. But I need to show posts and pages together sorted by date.
    Is it possible to do this without a plugin?

    #1583916
    Elvin
    Staff
    Customer Support

    Hi,

    As I understand it, the plugin can display posts or pages. But I need to show posts and pages together sorted by date.

    To clarify: You mean both the post and pages are within the same list? or do you mean they are separated into 2 list within a page? Let us know.

    Is it possible to do this without a plugin?

    It is possible by writing your on wp_query but it’ll be waaaay more tedious to do than simply inserting a shortcode from a plugin.

    A wise man once said:
    "Have you cleared your cache?"

    #1583970
    Vlad

    Yes, I need both the posts and pages are within the same list.

    #1583984
    Elvin
    Staff
    Customer Support

    Yes, I need both the posts and pages are within the same list.

    You can actually do this with WP Show Posts. In fact, this has been done before.

    Read about it here.
    https://wpshowposts.com/support/topic/including-more-than-one-post-type/

    A wise man once said:
    "Have you cleared your cache?"

    #1584075
    Vlad

    Sorry, I don’t know PHP.
    I have changed line 383 in the “wp-show-posts.php” file accoding this instraction: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de

    But where should I paste this code:
    add_filter( ‘wp_show_posts_shortcode_args’, function( $args, $settings ) {
    if ( 123 === $settings[‘list_id’] ) {
    $args[‘post_type’] = array( ‘post’, ‘another-type’, ‘one-more’ );
    }

    return $args;
    }, 10, 2 );

    #1584091
    Elvin
    Staff
    Customer Support

    Sorry, I don’t know PHP.
    I have changed line 383 in the “wp-show-posts.php” file accoding this instraction: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de

    We highly discourage editing of plugin files. If you must change something in how the plugin works, use filters instead.

    But where should I paste this code:
    add_filter( ‘wp_show_posts_shortcode_args’, function( $args, $settings ) {
    if ( 123 === $settings[‘list_id’] ) {
    $args[‘post_type’] = array( ‘post’, ‘another-type’, ‘one-more’ );
    }

    return $args;
    }, 10, 2 );

    for this particular snippet, you’ll have to change 123 to the ID of your WPSP list. You’ll also have to change/add/remove things on this line $args[‘post_type’] = array( ‘post’, ‘another-type’, ‘one-more’ ); to only $args['post_type'] = array( 'post', 'page' ); since these are the only ones you want to include on the list.

    Note: Be mindful of and within your code. These will cause issues. Use ' instead.

    As for how to add PHP snippets to your site, check this brief documentation:
    https://docs.generatepress.com/article/adding-php/

    A wise man once said:
    "Have you cleared your cache?"

    #1584126
    Vlad

    Thanks, it works!

    If you must change something in how the plugin works, use filters instead.

    Can you explain how to use filters?

    #1584742
    Tom
    Lead Developer
    Lead Developer

    Filters are basically snippets of code that change the output of core functions in the theme without having to actually edit the theme itself (which is never a good idea).

    #1584940
    Vlad

    Sorry I do not understand.
    You do not recommend editing the “wp-show-posts.php” file, but how can I replace this code:

    $args[‘post_type’] = array( ‘post’, ‘another-type’, ‘one-more’ );
    $args[‘post_type’] = array( ‘post’, ‘page’ );

    Do I need to use filters? But how to do that?

    #1584984
    Leo
    Staff
    Customer Support

    As for now, you’d need to do both steps Tom specified here:
    https://wpshowposts.com/support/topic/including-more-than-one-post-type/#post-13241

    First, you’d need to make the change Tom suggested to the wp-show-posts.php.

    Then add the snippet using one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1585326
    Vlad

    Thank you very much!

    #1586171
    Leo
    Staff
    Customer Support
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.