Half-Elf on Tech

Thoughts From a Professional Lesbian

Category: How To

  • Display Videos Shortcode

    Display Videos Shortcode

    This is a one-off, but it’s interesting to me so I’m sharing. I have a site with very pretty archives. It came with a video Custom Post-Type, but no archives for that type. Now I could have edited the theme, or overwritten the CPT, but I decided instead to embrace what I had and add on. What if I made a shortcode for [recent-videos] that showed me the recent videos?

    This code was specifically designed for the custom post-type ‘Videos’ in the News Theme by Theme Hybrid.

    add_shortcode('recent-videos', 'recent_videos_shortcode');
    function recent_videos_shortcode($atts) {
    
            extract( shortcode_atts( array(
                    'posts_per_page' => '10',
            ), $atts ) );
    
            $args = array(
                    'post_type' => 'video',
                    'posts_per_page' => $posts_per_page,
            );
    
            $vidlist = new WP_Query($args);
            if ( $vidlist->have_posts() ):
                    $return .= '<div class="display-vidlist archive" style="margin: 0 0 0 -20px!important;">';
                    while ( $vidlist->have_posts() ): $vidlist->the_post(); global $post;
    
                            $image = '<a class="image" href="'. get_permalink() .'">'. get_the_post_thumbnail($post->ID, thumbnail, array('class' => 'news-thumbnail')).'</a> ';
                            $title = '<h2 class="entry-title"><a class="title" href="'. get_permalink() .'">'. get_the_title() .'</a></h2>';
                            $date = '<div class="byline"><abbr class="published" title="'. get_the_date('l, F jS, Y, g:i a') .'">'. get_the_date('F j, Y') .'</abbr></span></div>';
                            $excerpt = '<div class="entry-summary"><p>' . get_the_excerpt() . '</p></div>';
                            $output = '<div id="post-'. get_the_ID() .'" class="hentry videos publish author-'. get_the_author_meta( 'user_login' ) .' has-excerpt">' . $image . $title . $date . $excerpt . '</div>';
                            $return .= apply_filters( 'display_posts_shortcode_output', $output, $atts );
    
                    endwhile;
    
                    $return .= '</div>';
            endif; wp_reset_query();
    
            if (!empty($return)) return $return;
    }
    

    The heavy lifting was formatting it to look right, and I’m not happy about my hack in class="display-vidlist archive" style="margin: 0 0 0 -20px!important;" but I also wasn’t 100% sure I wanted to separate the css just yet.

    Most people will need to change 'post_type' => 'video', to their CPT, and remove the style hack.

    I can already see where I’d extend this if I wanted to allow more arguments. The only one I put in was for the number of posts: [recent-videos posts_per_page=10] — You could easily add in one to allow ANY post type:

    function recent_videos_shortcode($atts) {
    
            extract( shortcode_atts( array(
                    'posts_per_page' => '10',
                    'post_type' => 'post',
            ), $atts ) );
    
            $args = array(
                    'post_type' => $post_type,
                    'posts_per_page' => $posts_per_page,
            );
    

    Then call [recent-videos post_type="video"] — Of course, if you do that, you should probably fork this into ‘Recent Posts Shortcode’ and rebrand recent-video to something else.

    Which you totally can do (this, as with all my code, is licensed GPL2).

  • SSL Self Certification and WordPress

    SSL Self Certification and WordPress

    I wanted to lock a single-site WordPress install down to use SSL admin because I’m a tin-foil hat wearing nerd. Or more to the point, I detest the idea of clear-texting passwords! Most of my problem was finding directions. See, I knew I had to add define('FORCE_SSL_ADMIN', true); to my wp-config.php file, but when I did that, I got an error:

    SSL error on chrome

    Turns out I’d never turned on SSL for my server! My problem then became that I don’t want to shell out $100 a year for SSL when it’s just me no my server, no one else. Once I determined all I wanted was to create an SSL Self Signed Certificate on my server, which has WHM, it got a lot easier!

    There are drawbacks to self-signing.  Firstly, every time I login on a new browser, I have to tell it ‘Yes, trust me!’  That’s annoying.  If I was using this for other things, I’d have to remember to type in httpd every time, but WordPress is smart enough to redirect that for me.  Also, back in the day, Chrome was an idiot about them and wouldn’t let me use them!  but I use self-signed without knowing it for ages, because my host set that up for cPanel and WebMail.  I’m not a business, it doesn’t bother me.  If I was, I’d charge more and shell out.

    Chrome Cert Alert

    All that error means is that “Hey, ipstenu.org signed this, and I don’t know who that is!” If you read further on that page, there’s a link to ‘Help me understand!’ and it explains:

    In this case, the certificate has not been verified by a third party that your computer trusts.

    Which is 100% true. By self signing, I’m skipping 3rd party verification and telling you to trust me. Looks scary, it’s really not if you know what you’re doing. If you’re willing to deal with this error every time you login on a new computer, then you too can SSL yourself to a little more safety!

    These directions will only help you if you’re using a VPS or dedicated server. You’re going to do all the work in WebHost Manager.

    1. Go to Main >> SSL/TLS >> Generate a SSL Certificate and Signing Request
    2. Fill in the fields – the passwords have to be alphanumeric, and remember to use the right domain. If you use www.example.com as your default, use that.  I use just example.com for all my sites so I did that.
    3. Save the data to a text document.
    4. Go to Main >> SSL/TLS >> Install a SSL Certificate and Setup the Domain
    5. Import your certificate data (or paste in from text)
    6. Select Submit

    If it works, Apache will restart and you’re done!  If not, you have to read the error.  My problem came with the domain details:Browse/details

    I was able to skip steps 1-3 and just go right to ‘browse’ since, apparently, at some point I’d done them before.  The problem was for my second site, it’s on my shared IP, which meant I had to put in the User of ‘nobody’ instead of the user name.  Not a big deal.

    After that, I was done and could log in to my site via SSL!

    But wait… What about MultiSite?  Well if you’re using subfolders, this is great.  Subdomains, however…  See the host name has got to be the domain name:  halfelf.org in this case.  So if I wanted to make one for all my subdomains… Owch.

    Then I thought that maybe, just maybe, the computers were smart enough on their own.  So I did this:

    Create a New Cert - Wildcard

    And then this:

    Wildcard certificate install

    Now, since I already had an ipstenu.org cert, I had to delete that one first. But once I did it, I was done. I turned my multi-site into something a little more secure!

    And now you can too.

  • WordPress and the Erroneous Update Message

    WordPress and the Erroneous Update Message

    DebuggingIt’s time for a little example in debugging!

    This domain is running WordPress trunk.  When I say that, what I mean is I’m running the very latest SVN, no more than four hours behind, thanks to a cron job.  At the moment I’m writing this, I’m on revision 18690.  I did this so that I could get off by butt and actually test thing without having to think about it.  To a degree, it tells you how much trust I have in WordPress and the core commit team.  My whole site runs because they know what they’re doing.

    This doesn’t mean there aren’t errors, though.  So far I’ve been very “helpful” breaking the responsive CSS on the admin dashboard.  I’m sure Helen, Andrew and Andrew just adore me right now.  Yes, that was sarcasm.  My methodology is pretty straight forward.  Just Use WordPress on ipstenu.org.  If I find a problem, make a note and bring up my local install.  I can only do this at home, on my Mac, so usually I come home with three or four notes.  Update SVN manually on ipstenu.loc (yes) and ipstenu.org.  Is the problem still there?

    Most of the time the problem goes away.  When it doesn’t, I take a screenshot and make a trac ticket (though perhaps I should add them all to the one ticket… if any of you core folks wants to tell me, please comment away!).  I’ve also taken to popping onto the IRC channel -ui and chatting with people there before trac’ing.  Last night I found one, told someone working on the project, and she patched it right then and there.  Teamwork!

    Yesterday, I noticed my ipstenu.org site had a weird problem.  I have a subsite on the network called test.ipstenu.org (feel free to check it out).  It’s just there so when someone says “When I use this theme/plugin…” and I can quickly go look.  I make fake posts, etc etc.  It’s quite seriously just for testing.  At one point, I’d spun up bbPress on that site.  I’d since turned it off, but it was on RC4.  RC5 just came out this week, and I had an update message on only that site, telling me to upgrade it.  Instead I deleted it.  That made the update notice go away on my network dashboard, like it should, but not on test.ipstenu.org.

    Say what?

    I tried to reproduce this like mad.  I installed bbPress RC4 on my local box, activated it, left it active, deleted it, and pretty much every which way I could think of to break it.  The error only happened on that site, even though bbPress had been running on another subsite as well!  I checked on multiple browsers, and wiped cache, logged out, nuked cookies, etc. Multiple computers even! Finally I gave up and said “I need help.”

    Weird WordPress MultiSite Question

    I have a multisite and one site on that network is showing that I need to update a plugin. Every other site correctly says “No Updates!” This one doesn’t.

    I’ve poked around, but I had assumed (bad me) that the admin bar would cache that network wide, somehow. But then why is it only on one site? So I wiped and rebuilt the wp_10_options table and it still shows up.

    I haven’t the foggiest idea why it’s happening. Luckily this is only on my test site, test.ipstenu.org, but it’s maddening.

    I don’t find a huge amount of use for Google Plus, but that was great for me.  I posted, I tagged it with my WordPress circles, and went to catch my train.  It was too long for a tweet, too weird for the forums as I didn’t want people to get fussy – I’ve noticed if I raise a post, it scares people.  I guess I have ‘street cred’ on WP and some people worry when I have a problem I can’t fix right away.  Flattering.

    I got replies from Raincoaster, Brad, Ron & Andrea, and Otto, who all said “That is weird.”  Andrea pointed out that it could be caching.  Brad asked about plugins.  Otto and Ron said that if it was cached, it was network wide (which made it even weirder to only see it on one site), and then Ron told me to look in wp_sitemeta table.  I was, I admit, already looking there, but I’d gotten distracted when I found the “Add a Link” page was broken on trunk.

    Fancy Pants ManAfter Ron’s comment kicked my pants, I went to that table and thought to myself “Where are the caches?”  I knew this from ages back, that anything named _transient… was a cache.  There are tons of transient feeds in your wp_options table because the RSS feeds you see on the dashboard are cached.  Cool, right?  Well, what if, just what if one of them was corrupted?  You can delete them without hurting your site!  So I hovered my mouse over the update alert and noticed the mouseover said “1 Plugin Update.”  Then I looked at the transients and found this:

    _site_transient_update_plugins

    And I deleted it.

    And my error went away.

  • Multiple “Share This” On Your Front Page

    Multiple “Share This” On Your Front Page

    So you want people to be able to easily share your posts, and you install Jetpack and configure it so that the happy icons only show up on posts and pages (since you can’t make it show on only posts).

    Share This Settings

    Then you decide to make a Static Front Page so everything looks pretty. Except you get multiple instances of the sharing links! That isn’t what you wanted at all!

    The problem is that the when you make a static front page, it’s actually not an index page. It is simply a page using a template. Strictly speaking, it’s not an archive page, nor an index page, and because of that it’s treated like any other page and the ‘share this’ settings treat is ‘correctly’ by showing itself every time a page/post is called. I did report this to Jetpack, by the way, and they were a bit torn on if this is Jetpack being silly or something that needs to be addressed in core (that is, does WordPress need to grow up and treat a static front page as an index page).

    While they’re hashing this out, you can fix it yourself, which is a relief to those of us who ran into this.

    The easiest (and actually best) way is to use the WordPress template hierarchy to your advantage. If you use a front-page.php file instead of a static front page, WordPress knows that it’s an index page. This is the best way because you don’t make any extra ‘calls’ to the code. WordPress tucks it away on it’s own. To do this, if you’re using a page template, just copy the template (say page-snarfer.php) into front-page.php and call it a day. Depending on your theme, you may need to add a call to any special classes being called. (I know that if you use Hybrid Core, you need to add a call to page-template-home for it to format right.)

    But sometimes you can’t do that. Like if you’re on MultiSite and you use the same theme for multiple sites and you don’t want them all to have the same style of front page. Well now we have a minor problem. First thing to do is turn off sharing for the page you’re using as the static front page.
    Turn off sharing

    Doing just that brought me to this:
    One Less Share This

    In this case, I’m using a static front page with some content, formatted via the Twenty Eleven “Showcase Template” to show recent posts below my content. The first post shows up as an excerpt and then the rest show as titles with links (apologies for the different color):
    Multiple Posts - One Share This

    So for this theme it works perfectly and I’m happy as can be. This method also works if you’re using a Static Front Page without a page template!

    Double Rainbow For The Win But. That doesn’t work for all themes. And this is where we have to do the ugly things we don’t want to do. We have to edit CSS. In and of itself, this is pretty easy but I think it’s a poor choice because all this will do is hide the icons from displaying, and that means the code still gets rendered and call and that means you’re putting more work into loading your page than you need.

    Sometimes you just can’t fix it the best way, and acknowledging that, here’s how to do it. First, you must be using a page template for your static front page. (I said this once before, but it bears repeating: If you’re not using a page template, you can fix this by just turning off the sharing for the page.) Open up that template and look for something like this:

    <div id="primary" class="showcase">

    Once you’ve found it, you just have to add in a CSS call:

    div#primary.showcase div.sharing {display:none;}

    That says “In the primary.showcase div, if anything’s using the div sharing, hide it.” Not the most elegant or efficient way about it, but it gets the job done.

  • Lion: Switching F4 to run Launchpad

    Lion: Switching F4 to run Launchpad

    How about a (mostly) pluginless solution?

    I don’t use the Dashboard on my Mac, I’ve never really gotten the hang of the widgets and I just don’t like ’em. If you happen to use FunctionFlip to turn that off, you get ‘Application Window’ instead, which boggled me even more. What good was this? But I do like LaunchPad because I can sort through my apps really fast. Like many of you, I saw the fixes using Function Flip and Quicksilver, and hated the idea of running multiple apps to do something.

    You don’t need any!

    This is a two step process that requires you to go into System Preferences > Keyboard > Keyboard Shortcuts.

    Click on Mission Control

    Double Click on the F4 to the right of Application Windows and the field will become editable. I changed my to Apple-F4:

    Then go to to Launchpad and Dock

    Check the box by Show Launchpad and that will make the option editable. Press F4 and you’re done!

  • How to Ask for Help

    How to Ask for Help

    Imagine you’re at the coffee shop and you make your order. Plain coffee. The guy behind you jumps up, RIGHT as they’re making your order and shouts “I want the exact same thing, but a latte with no foam!” Then the guy behind him chimes in “I want an espresso!” and “I want a hot cocoa!”

    What happens to the people behind the counter who have just gotten a dozen different orders all at once?

    You end up with a bad coffee, that’s what.

    That’s why I tell people to make their own topics.