A wordpress coding or maybe plugin question

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.33 out of 5)
Loading...
By Oliver (AKA the Admin) on 22 comments
in Categories: Just Talking

Hello guys !

For those of you who are in it and who wouldn’t mind losing a few minutes, could I ask you a wordpress question, please ? :)

You may have noticed (wink, wink) that my posts start with a big image.

I’m thinking about adopting a new theme for my blog, but one of the obstacles is that my blog posts don’t have a “featured image”, that very special image the blog engine considers as representative of the post, and that will be adjusted to the devices of the visitors.

Normal size for the “real monitor master race” (only half-trolling, it may be practical, but god the shit small screens cause everywhere, it was simpler before), adjusted sizes for the various devices, and possibly thumbnail if I want to choose a theme displaying thumbnails at some point (honestly, no idea if I’d use that post-thumbnails feature yet).

But, as I told, nope, my posts don’t have a featured image. So, applying a modern theme making use of featured images to my blog posts would, quite ironically, make these posts appear as if they didn’t have an image on top of them, or would break their appearances on devices with a small monitor.

Fortunately, some themes work great with wordpress, and I noticed that
– if I choose a cool “made for responsive design” theme, and
– I open a blog post
– I click to update the blog post
(even though I didn’t change anything inside it !)
… –> then, thanks to this plugin, my “on top of the post” image will be considered now as “THE” featured image.
With all the advantages coming alongside it.
– and yet, looking at the code of the post, the post’s html is still exactly the same
! O_o In my eyes, that’s magic, but magic that works (once again, it’s thanks to this plugin).

So I thought : cool, I just have to open all my blog posts, update them, and I’m done.
Problem : since its creation, I published 8834 posts on Hentairules.
That would… take some time :twisted:

And so, here comes my question : would you have an idea about how to perform a batch/cron/planned/scheduled/pluginized/progressive/whatever update of all my blog posts, so that wordpress is give a chance to reconsider its featured images for the blog posts ?

I thought of going to the posts management page, select a group of them, click to batch Edit, and then click to batch-save.
You can do that in wordpress, it doesn’t open invidual post editing windows, it’s cool.
Sadly, it won’t work if I select a large number of posts. Even trying to do it for a group of 50 posts is already too much.
Reason is : that’s actually been done through the generation of a query URL sent to my server, and the total URL to send that query is already over 2000 characters (and this legitimately blocked by my server) for a minuscule batch of 50 posts.

So, it’s got to be another way to do it.

Anyone having suggestions ? ;)
Thanks if you can :)

Subscribe
Notify of
guest

22 Comments
oldest
newest most voted
Inline Feedbacks
View all comments
Guest
Guest
9 years ago

What OS is your server using? What are you using?

Oliver AKA The Admin
Admin
9 years ago
Reply to  Guest

Debian wheezy with LAMP, latest stable wordpress (what, 4.1 I think ?)

Noah
Noah
9 years ago

Hi, I'm a web dev with a few years on WP. There's actually a plugin that will auto use the first image as the featured image if one is not set. https://wordpress.org/plugins/auto-post-thumbnail

That one is tested up to version 3.6 (I assume you're on 4.1) but it should still be good.

If it doesn't work I know another one that's a paid for option but it's only $8 (woo hoo tax write off)
http://codecanyon.net/item/auto-post-thumbnail-pr

Noah
Noah
9 years ago
Reply to  Noah

Also, if neither of those work for you, I can write you up one real quick to drop into your theme

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

Thanks Noah !

I'll look into that plugin to see if it does the job :)

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

I just tested, this won't parse old posts, only affect newly created posts. Ah, too bad ^^

Noah
Noah
9 years ago

oooohkay, people are throwing out a lot of tech questions that just aren't needed.

If you already know what theme you want to use, send me a link and I'll tweak it to grab the featured post or the first image if it doesn't exist.

It really should only take like 20 minutes.

My email is should be visible to you in the wp admin panel. Shoot me an email and I'll be happy answer any questions you have

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

Hi again Noah,

I'm thinking of adapting the popular Hueman theme for my needs, it would serve very well for an all-purposes basis.

However, this would be an unending server resources slaughter if the theme were to re-process itself every time, do you see the idea ?

It's already going to be costy in terms of CPU to update all the posts, sure, not all at once, but even then, mysql is going to have work to do.

We can't allow a theme to do that every time, it needs only be done once.

The "great" idea here, is that once we go through the process of updating the posts, it's done, it isn't necessary anymore to re-update them.

I'll also have to update my initial post, I didn't even realize I had this plugin on the test blog already : https://wordpress.org/plugins/auto-post-thumbnail
That's the one that cause top images to become featured when a post was updated.

So, top images didn't become featured by miracle, but thanks to an already existing plugin.
Sorry for the confusion this may have caused !

(the reason for this confusion : I'm working on a new theme when I have time, here and there, and my wife is helping, she installed this plugin. Apparently, she did told me, only I wasn't listening. I'd tend to believe her, that won't be the first time I'm too distracted like that -_-)

Noah
Noah
9 years ago

I'm confused about why you would need need to update those posts at all anymore then if the plug is moving the image where you need.

This is what you want right? (and correct me if I'm wrong)

>When displaying a post
>Display Post Thumbnail where it's supposed to
>If Post Thumbnail does not exist, get the first image in the content of the post
>Display that image where the Post Thumbnail is supposed to be

If what I typed in above is what you need, then it's a simple thing to program into wordpress that will not require any updating of the posts in the Database

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

That's not working like that ^^

This plugin only works when a post is updated or published.

When one of those events happen, the plugin will check for the presence of a featured image, and if none is present, it will do its magic and make the first embedded image THE featured image.
(Where the hell are featured images registered as a thing anyway, since the post's source code remains unchanged ?!?)

This isn't a "rewrite on the fly" plugin, which would be a resources-devouring ogre…

In the light of all this, we can rewrite my question like that :
— I need what this plugin is doing during a post update doing applied to every post of mine

Oliver AKA The Admin
Admin
9 years ago

Looking at http://codex.wordpress.org/Function_Reference/wp_
(or http://wpseek.com/function/wp_update_post/ )

it would seem the solution would lie less in looking at featured images, and more at the very act of updating posts. Although I'm not sure how it goes, with that function above, if it's possible to edit a post with zero change, even though that does happen when I do it within the bulk posts editor in wordpress, selecting a (regrettably very small) group of posts, bulk updating, bulk saving with zero changes…

Aaaargh >_<

Trav
Trav
9 years ago

I'm not sure what wordpress changes exactly when you "update" a post but if it's looking at for example timestamps in the database to see when it was last updated you could "update" them with a simple query just updating all the timestamps to a current timestamp

oldbrokenhands
oldbrokenhands
9 years ago

Let me see if I have all this correctly:

1. Wordpress basically offers a RESTful type interface for publishing webpages/blogs.
-POST (for creating pages)
-GET (for reading pages)
-PUT (for updating pages)
-DELETE (for deleting pages)

2. You want to use the PUT/update feature of Wordpress to load a template that allows you to use the preview pic from your posts as the default pic that the Wordpress layout rules requires.

3. I'm assuming that all this is done with CLI, but that the CLI has a limit on how many posts it can handle at once?

4. So what you would need is a CLI program/script that would load the list of post IDs from a file into an array, and then the Wordpress CLI would take chunks of IDs from the array and PUT/update the pages until the end-of-file is reached and the array is empty.

Is this pretty much the gist of what you're asking for?

Oliver AKA The Admin
Admin
9 years ago
Reply to  oldbrokenhands

I'll bring clarifications here and there, Oldbrokenhands, but you may also look at the answer I made to Noah above, in case I'm forgetting something (cross references for safety, let's say ^^) :

– the RESTful interface is a brand new word to me. I'm familiar with post-get-put as I had to parse server log for stuff in the past, but I didn't have a "consolidated" view of it all as applied to worpdress, that goes to show the extent of my knowledge (huhu, not much)

– how an image becomes featured.
I screwed up with my post description about that one, entirely by my fault, I had failed to realize something, how images were becoming featured.
It's thanks to a plugin that was mentioned in the discussions above : https://wordpress.org/plugins/auto-post-thumbnail
My wife, who is helping with trying to make a responsive design theme, had installed it, and I carelessly didn't pay attention when she told me she installed it. I imagined it was the wordpress' magic or the theme's magic that was making images become featured after an update, turns out I was wrong;

– Every CLI is going to have a limit on how many posts can be handled at once, so batches of small numbers of posts will have to be processed, not everything at once.
Which CLI are you referring to, shell, mysql through shell, phpmyadmin ? ^^

I *think* it would need to be handled through wordpress itself (which can take cron, it has its own cron system), since we need the wordpress internals to "hear" there is a request to update a post, and thus trigger the plugin's components who will, in the wake of this request, make the top image featured.

oldbrokenhands
oldbrokenhands
9 years ago

Sorry, still have RESTful in my head from a school project. Basically it's just a new trend of describing the CRUD (create, read, update, delete) method that's been a part of programming since the dawn of coding.

I was referring to shell (like BASH) CLI, I thought wordpress had a shell command like other sites such as github and cloudhub.io for example.

With a shell script you could load a file with post IDs into an array then, put the array in a loop that runs until all your posts are updated. Inside the loop you'd set a limit for the amount of posts that are handled during each iteration of the loop. But if WP has some kind of GUI or CLI of its own, then you'd be limited by what WP allows.

Anyhow, I reread Noah's post and he seems like a guru about web dev. I'm just trying to reach an agreement on what the problem is by restating what I thought I heard. It's a habit I've picked up as a tech troubleshooter. It allows all involved to be on the same page (communication-wise).

Noah
Noah
9 years ago

Sorry, replying to myself here.

You said you wanted to use this theme right?
https://wordpress.org/themes/hueman

I just made downloaded it and made the necessary edits to display first images in the post as the featured post if it doesn't exist. No need to reconfigure any old posts.

Just let me know where you want me send the files

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

I thought this would require complicated database operations, and now you're telling me simple template editing will do the job ? O_o

YESSSSS !!

Could you simply zip it, and post it to some website like mediafire, sendspace, depositfiles, dropbox ? Thank you so much :)

That said, doesn't it come with a price ? I mean, it's bound to require added CPU or Mysql usage with every new display of a post or of the index, won't it ?

While the solution to make featured the top images wouldn't generate this added CPU load ?

(I may be mistaken about that)

Noah
Noah
9 years ago

Yeah, it's simple template editing.

I suppose there is a small Mysql, however it would be negligible. We're talking a fraction of fraction of a percent here.

There is nothing special my code does, it simply checks for a post_thumbnail (which the theme already did by default) and if there isn't one, it will grab the first image of the post, and if there isn't one of those, it shows that default gray image.

I tested this locally and it worked just fine so let me know if it works for you

Here is a link to the zip on mediafile: http://www.mediafire.com/download/i72bn0dzi5vi0hg

Just replace the files in your theme with those and you're good.

Added Lines:
content.php: 8-9
content-standard.php: 8-9
content-featured.php: 8-9
functions.php: 828-842

Noah
Noah
9 years ago
Reply to  Noah

Did that work for you?

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

Haaa!
I didn't see your comment ! O_o

I'm busy today, I'll check it this evening. Thank you!!

Oliver AKA The Admin
Admin
9 years ago
Reply to  Noah

Hello Noah !

I'm not forgetting about you, thank you again :)

I tested and, yes, it works !!

Now, I'm experimenting with making a child theme and the bits about it.

I'll come back another day (haaa, time… never having enough) to you to report about it and how it's been doing, haha, thank you again ^_____________^

Noah
Noah
9 years ago

No prob! I'm glad I could help. Let me know if you have any more questions