Site logo

Archived topic

Control posts shown on first page of blog

35 replies · Started by Conor on September 16, 2020

Viewing posts 16–30 of 36

I see.. Well I just tried wp show post, and although it is really cool and maybe useful elsewhere, it unfortunately, doesn't work either.

The title can't be moved below the posts, the spacing of the posts doesn't work well.. https://conorwriter.com/2929-2/

But, I have another idea.

Could we write code to say no posts show up on home page? It seems like sticky posts ignore all the rules so if we say no posts, it should make it so only sticky posts show up.

I tried this and it didn't work:

add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
function tu_change_posts_per_page( &$query ) {
if ( ! is_main_query() ) {
return;
}

if ( ! $query->is_paged ) {
$query->set( 'posts_per_page', 0);
}
}

The only other solution is to make it so sticky posts don't have post dates, or make it so they always have a post date = current time. The only issue I see with that is that it will cause a bad rss experience.

or maybe i can make the home page only show posts dated on a certain date. then I can just put the 6 posts i want on the home page to be set to that date

The title can’t be moved below the posts

Have you tried changing the image location?
https://docs.wpshowposts.com/article/images-overview/#image-location

What about the spacing that doesn't work?

Could we write code to say no posts show up on home page?

I'm not sure unfortunately. Doesn't seem logical to set the front page to be the posts page but also don't display any posts.

You could try checking with WordPress support on whether this special case would work - if they can help with the code that works with a twenty series default theme, it would work in GP as well.

WP Show Posts with some tweaks is still the best option in my opinion.

I’m not sure unfortunately. Doesn’t seem logical to set the front page to be the posts page but also don’t display any posts.

well, the idea is that sticky posts don't listen to the rules, so if we say show 0 posts on home page, my 6 sticky posts should still show up. Problem solved.

or if we can make front page only show posts from a certain category or from a certain date, then i'm golden

I would still recommend using WP Show Posts with a static home page to do this.

Did you see my suggestion above about change the image location in WPSP?

We can likely use a bit of CSS to tweak the WPSP content if they are simple enough.

That does help to put the image above, but there are still a ton of issues,

https://conorwriter.com/ - here is what I want it to eventually look like. 6 sticky posts and that is all.. ( I set it manually for now by changing the dates.. ) ( just worried about using this method because it might mess up RSS - maybe just take these 6 posts off RSS ? )

Here is what wp posts looks like - https://conorwriter.com/2929-2/

The images don't have a hover over effect, the headline is a link so it is blue, the images are a different size and I don't think I can easily fix that, and so on and so forth.

So,

is there no way to either:

1) Since sticky posts don’t listen to the rules, so if we say show 0 posts on home page, my 6 sticky posts should still show up. Problem solved.

or

2) Can we make the front page only show posts from a certain category or from a certain date, then i’m golden

thanks for all the overtime on this one.
C

The same image hover effect can be achieved with this CSS:

.wp-show-posts-image:hover img {
    opacity: 0.7;
}

Title color can be changed with this CSS:

h2.wp-show-posts-entry-title a {
    color: #000000;
}
h2.wp-show-posts-entry-title a:hover {
    color: #0f74b5;
}

Hopefully that gets you closer :)

Would neither of these ideas work?

1) Since sticky posts don’t listen to the rules, so if we say show 0 posts on the home page, my 6 sticky posts should still show up. Problem solved.

or

2) Can we make the front page only show posts from a certain category or from a certain date? If so, I’m golden

thanks for all the overtime on this one.
C

Hi Leo, that will work perfectly! I'm just having trouble making it work..

function generate_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'category_name', 'home-category-slug' );
}
}
add_action( 'pre_get_posts', 'generate_home_category' );

Do I put the category I want to show up on the home page to be in the 'category_name' and then do I put its category slug to be in the home-category-slug?

C

You would replace home-category-slug with the slug of the category.

function generate_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( ‘category_name’, ‘secret-category’ );
}
}
add_action( ‘pre_get_posts’, ‘generate_home_category’ );

I put this in and it didn't work for me. I also tried a couple variations of my category in the category_name, but it didn't work.

Not sure if this got lost:

function generate_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( ‘category_name’, ‘secret-category’ );
}
}
add_action( ‘pre_get_posts’, ‘generate_home_category’ );

I put this in and it didn’t work for me. I also tried a couple variations of my category in the category_name, but it didn’t work.

Thanks for everything, Leo and team, really appreciate the help

This archived topic is closed to new replies.