Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments are being displayed in the carousel #29

Open
jscultureshift opened this issue Jun 24, 2020 · 3 comments
Open

Comments are being displayed in the carousel #29

jscultureshift opened this issue Jun 24, 2020 · 3 comments

Comments

@jscultureshift
Copy link

I am using the recommended code to add the Medium carousel to the homepage and if there's a comment added to one of the posts it shows up in the carousel.

@mike820324
Copy link

mike820324 commented Aug 7, 2020

Hello everyone,
I'm also encounter this issue in my wordpress site.

After a further investigate about the solution, I have found a workaround propsose by this link
The workaround provide a simple heuristic way to distinguish between comment and post.

As the website suggest

BUT! it’s always an empty array of categories when the item is a comment. So it’s nothing harder than just filter the whole response array from items, where categories == array.length > 0. Let’s do this!
We can check the categories array length and if it's greater than zero, we show the post.

A simple digging about the source code, I found out that we can simply add a comparison below the for each scope

foreach ($posts as $post) {

The code snippet may look something like the following

if (count($post->categories) == 0) {
  continue;
}

The only side effect I can think of is that if a post does not have any category, it will be consider as comment and as a result will not be shown.

@acekyd Any thoughts about the above fix.
I would love to submit a MR if the above workaround is okay for you.

@acekyd
Copy link
Owner

acekyd commented Aug 11, 2020

Hello @mike820324, I came across this same fix online but the edge cases were why I hesitated to implement it. Doesn't seem like there's a better alternative.

To send the PR, would be great to include an attribute so the user can set if they want to turn comments off instead e,g [display_medium_posts handle="@acekyd" comments=false]

@mike820324
Copy link

mike820324 commented Aug 25, 2020

@acekyd thanks for the reply.
After digging the medium API for a while, I have found a solution to get the user post with the medium GraphQL API.
By using the GraphAPI, the above side effect that mentioned earlier will no longer exist.

The underline investigation and code snippet can be found in my medium post
https://medium.com/@mike820324/web-crawler-getting-medium-post-a6e52fd36fd6

I'll try to implement the GraphQL into the PHP version.

[display_medium_posts handle="@acekyd" comments=false]

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants