Wordpress

Shortcodes, Widgets, ‘n Duct Tape

Even cats know that duct tape is useful


cc licensed ( BY NC SD ) flickr photo shared by Rev. Xanatos Satanicos Bombasticos (ClintJCL)

It comes in handy for PHP work on WordPress sites as well. You should know that the main internal organ that makes the magic of the ds106 site do what it does is the Feed WordPress plugin. This is what allows us to add external blogs to be auto republished inside our site, and as well resyndicate it out to our satellite sites.

We have over 560 blogs that ds106 checks on a regular basis.

One of the challenges is that the administration of Feed WordPress (hereto after called FWP) is really manual. The main page lists them all in one giant list. And if anyone changes their blog, we have to update it inside the interface. In fact, until Martha recently put together the magic, the sign up for the site required one of us to manually enter the feed into the system. This is now automated (and awesome) (unless someone enters a bad URL).

A real problem for us on being able to do more with this is the data structure of FWP. It’s a pretty complex plugin, and while I have looked through it, well it remains the problem of dealing with OPC (Other People’s Code). But the place it stors all the information about the feeds is weird- rather than using the database, it puts new feeds in as a Link, and stores all fo the info in a gnarly serialized array string in the notes field.

This makes it hard to do anything we’d like to do with the feeds.

This is why we aere looking forward to using the success of the ds106 Kick Starte projector to hire the plugin developer to make some changes. We had a productive skype call earlier in the summer, and outlined the things we desired.

I am not sure what happened, but I don;t think he ever responded with a quote or an interest. That’s why it was cool that Martha cracked the big problem, to automate the subscription process.

Another thing I wanted to have is a way to list more or less a blogroll for a subset of the feeds. You see when you sign up, if you are in one of the UMW classes, or other ones, like Michael Branson Smith’s York College class, we have FWP add an identifying tag to all incoming posts, so we can segregate them- like:

  • umwfa12s1 identifies Martha’s UMW section.
  • umwfa12s2 identifies my UMW section
  • cunyfa12 indeitfies Michael’s Yoirk class

We even add an openonline tag to any who is here on their own.

This means we can have URLs that aggregate just the posts for one of these groups. What I wanted was a way to list the blogs that were within each group.

The approach that seemed most flexible was to write my own short code so that we could use it in a page, post, or widget. A shortcode allows a special code in the text to be interpreted on the fly to insert other information.

What I have coded allows us to insert something like:

and this produces the sidebar widget at http://ds106.us/tag/umwfa12s1. This could have been done with ordinary WordPress links, but that is manual to edit. This is automatic. As feeds are added, the output will change.

I’d never coded a short code but they are super easy. I lifted mine from what I learned at a tutorial for wp tuts+.

This is code that goes into a themes functions.php file. The first thing is we have to tell WordPress to look out for a new shortcode:

This says to look for any shortcode named [feedroll] and insert whatever is generated by a function called ds106_feedroll (it is a good idea to prefix custom functions to keep it providing from any other function in the stack of stuff wordpress looks at)

Here is the function that does all the work – it is running a MySQL query to find the items in the links table that contain the tag in the notes field. It helps to have these cryptic coded tags!

My test of this is one that does this in a page, listing all of the blogs we subscribe to tagged openonline, using the <ol>…</ol> list tells us a total.

But where I wanted it was some widgets on the sidebar of the various URLs for the tagged pages. A problem is I did not want to create new sidebars for every one of these, so I made use of the widget logic plugin -for the sidebar in our theme that is called for each of these, I have a text widget and I use the logic like:

which means you will only see the content if it is a Tag archive page and the tag is umwfa12s1.

What I have in here is:

Here you can see we have some text at the top, the list of blogs, a URL for the RSS feed for this group of blogs, and… some stuff that links to ANOTHER custom script, this one that does something similar to the mySQL query above, but generates the output as an OMPL file that can be imported into an RSS reader (so people can get a subscription to the entire group of blogs).

This was code I wrote over the summer Dynamic OPML Files Generated from Feed WordPress.

So you can see these in action on the sidebars of our class pages:

As separate widgets, it allows us to put custom info in each classes listing, like I added a twitter list widget for my class.

Some of this is a bit kludgy, but the power of short codes is on me. So for now, we continue to hack together things as we see needs and what we can tape together.

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca

Comments

  1. I think everything said made a ton of sense.

    However, consider this, what if you added a
    little information? I mean, I don’t wish to tell you how to run your blog, however suppose you added something to possibly get folk’s attention?

    I mean Shortcodes, Widgets, �n Duct Tape – CogDogBlog is a little boring.
    You should peek at Yahoo’s front page and note how they create article titles to grab people interested. You might add a video or a picture or two to grab people interested about what you’ve got to say.

    Just my opinion, it would bring your blog a little bit more interesting.

    1. I think not much of what you said makes sense, but I took the liberty of removing your spam ridden URL link, and deleting your email address from this comment. Why, because this is my house and I make the rules.

      However, consider this, what if you actually read my blog post? I don’t wish to tell you how to write a comment, but whay if you actually were a real person intent on more than inject your lame ass URL into my site?

      I mean, your comment is a little boring.

      You should peek at my blog post and see how I have a photo of a cat playing with duct tape. What more do you need to grab your interest, frontal nudity and a dancing pig? You might try taking class on reading and learn how to understand what people are writing.

      Just my opinion, it would make your comment a little less likely to be marked as spam.

Leave a Reply

Your email address will not be published. Required fields are marked *