- This topic has 13 replies, 4 voices, and was last updated 1 year, 6 months ago by
Leo.
-
AuthorPosts
-
December 16, 2020 at 11:49 am #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.December 16, 2020 at 4:31 pm #1583614Leo
StaffCustomer SupportHi 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 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 16, 2020 at 11:17 pm #1583860Vlad
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?December 17, 2020 at 12:43 am #1583916Elvin
StaffCustomer SupportHi,
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?"December 17, 2020 at 1:21 am #1583970Vlad
Yes, I need both the posts and pages are within the same list.
December 17, 2020 at 1:30 am #1583984Elvin
StaffCustomer SupportYes, 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?"December 17, 2020 at 2:39 am #1584075Vlad
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/286caf1164db8b6b6f38b85d3a011b519a27f4deBut 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 );December 17, 2020 at 2:58 am #1584091Elvin
StaffCustomer SupportSorry, 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/286caf1164db8b6b6f38b85d3a011b519a27f4deWe 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?"December 17, 2020 at 3:38 am #1584126Vlad
Thanks, it works!
If you must change something in how the plugin works, use filters instead.
Can you explain how to use filters?
December 17, 2020 at 10:08 am #1584742Tom
Lead DeveloperLead DeveloperFilters 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).
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 17, 2020 at 1:15 pm #1584940Vlad
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?
December 17, 2020 at 1:56 pm #1584984Leo
StaffCustomer SupportAs for now, you’d need to do both steps Tom specified here:
https://wpshowposts.com/support/topic/including-more-than-one-post-type/#post-13241First, 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/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 17, 2020 at 11:32 pm #1585326Vlad
Thank you very much!
December 18, 2020 at 9:00 am #1586171Leo
StaffCustomer SupportNo problem 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.