Pulling wordpress post's img src to be background-image - php

Ok. So I have a wordpress plug-in that runs a cron job that reads RSS feeds, then parses the RSS feed title and excerpt into new posts.
Most of the time, each RSS 'post' that is read includes an img tag that is straight up html (ex: <img src="localhost/img/img-1.png">). That img is stored in a cache on my own wordpress server so it's visible without the need of the RSS server it was read from.
What I'm trying to do is to use the img tag src as the background-image for the post.
As of now, the only way I can see the image tag without loading the wordpress post, is by diving into the WPDB, finding the post and copying out the img src.
I've already tried using the post-thumbnails option, but since the image isn't loaded as a Featured Image when it's read from the RSS feed, the image isn't loaded into the Media library of the wordpress install.
My train of thought is leading me towards some way to parse the img tag src into it's own mysql table, but that is a whole bowl of noodles I'd rather avoid.
Is there an easier way to do this?

Related

Get page Body contents in MODX

My MODX site needs to grab the first image from all pages for Open Graph Meta tags, which will be plugged into the Head chunk for all templates.
The problem with this is that not all images are located in the content part of a page. Some are located inside Chunks and others inside TVs. (Finding an image tag from the content is not an issue.)
It might be possible to get all Chunks and TVs and loop through their values to check for images.
But is there a way to get the <body> contents of the resource?
Probably several ways, you can try writing a plugin to parse through the entire content of a page, looks like the OnWebPageComplete event may be the one to use (take a look at the different events to see if one is more appropriate}
You can try and grab the resource from the cache, keeping in mind that any chnks/snippets/TVs called in the page un-cached will not show up in the resource cache file.
You can get a list of TVs once you have loaded a resource & then use getTVValue to get the value.
If you have an image in a chunk, getChunk might work [might, I've never tried to use it that way] to get it's contents but I would image that the image in a chunk would come from a TV ~ so you should be able to retrieve it with getTVValue.
You could also just setup a TV for the OpenGraph image and explicitly set it on a page by page basis.
Probably writing a plugin & some regex is going to be the least painful way of going about it.

Wordpress Embedded Video Issue

I am having difficulty with a Wordpress site that has already been pretty heavily customized. Suddenly, one of the pages simply stopped working!
The issue is that when clicking a video link, a lightbox clone (prettyPhoto) is supposed to show the youtube video, but instead the popup message "Image cannot be loaded. Make sure the path is correct and image exist." displays.
Here is what I have learned so far on the issue through a lot of research and exploring the code:
The page is composed of individual posts and the images that the anchor tag is surrounding are generated using the video thumbnail of each post.
The posts themselves are merely a YouTube link "ex: http://www.youtube.com/watch?v=LdOKJ7cybi4" with a title and a video thumbnail.
The issue seems to be caused by the href attribute that Wordpress generates. Using the above youtube link example, it supplies a href attribute like this (it actually puts the span tags and everything inside of the href attribute):
<span class='embed-youtube' style='text-align:center; display: block;'>
<iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/LdOKJ7cybi4?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' frameborder='0'></iframe>
</span>
When I remove the span tags and all contents and replace it with the content of the post (ex: http://www.youtube.com/watch?v=LdOKJ7cybi4), then it works! But, I can't figure out how to make it use the YouTube link that was typed into the post, rather than generating these excessive and unneccessary span tags.
Help please!
It seems like wordpress is formatting your text. there are several plugins available to stop this happening for eg :
http://wordpress.org/support/view/plugin-reviews/ps-disable-auto-formatting
However, given that your site is already highly customized I would recommend exercising caution and perhaps backing up first.

How do I edit the html when using a PHP based CMS?

I am not experienced outside of HTML and CSS.
I have a site on a less well known CMS called Ushahidi. Editing CSS is fine but right now I need to change an img selection. Currently, an image on a page has the code:
<a class="photothumb" rel="lightbox-group1" href="http://trashswag.com/media/uploads/35_1_1347312096.jpg"><img src="http://trashswag.com/media/uploads/35_1_1347312096_t.jpg"></a>
I need to remove the ability of the site to use the second image (note there is a slight difference "_t.jpg" is appended to the second src.
How would I alter the site so as to select the first image only i.e. remove the "_t" string?
The version of the image with the _t in the name is probably a thumbnail of the first image. What you have there is a small image, that when clicked takes you to a larger image. If you want to display the full-sized image and get rid of the link, just use
<img src="http://trashswag.com/media/uploads/35_1_1347312096.jpg">

How to extract the full content from a partial content rss

I am working on a PHP project. The goal (in a simple lang) is to read an RSS feed, and get the title, full content, and media (video and/or images) from it, and post it in a wordpress blog. (The customer wants to use some sources that are open for sharing and use them for auto posting in his blog)
I successfully could extract the title, content and images or videos and post them in wordpress. However, there are some problems:
1) I can only extract the media if they are included in the RSS.
2) I cannot extract the full text of the content if the RSS is a partial content RSS.
So, is there any solution to be able to access the original content from RSS and extract the full text content and media if available?
The RSS provider decides if the full text is exported or not. So if it exports just the partial content, you may have to get the full content of the link by curl(or others) and try to figure out where the full content is.
If you provide a link to the rss feed I will update my answer to tell you precisely. This can only be determined on a case by case. An example of a reader can be found here http://www.w3schools.com/php/php_ajax_rss_reader.asp obviously with modern techniques you can do a lot better.

How do I turn a link into an image to embed?

I am attempting to create some functionality on beta.peaksneak.com where users can basically journalize. To do this I want them to be able to add images, videos, quotes, and links to a journal entry.
I found out that you can use oEmbed to embed videos, and images/quotes are easy.
Is there a script for embedding links and auto-capturing a large image from the link to use for embed purposes? For example, on Facebook, when I paste a link into a comment, it automatically generates an image and text (probably from meta tags and the first large image it can find).
You can also try https://github.com/starfishmod/jquery-oembed-all for your oembed stuff - it has a lot of providers and is client side only if that is what you are looking for?

Categories