In consulting You Show participants on their site organization, I am trying to help them see there are more opportunities for the front page than the long river of reverse chronological ordered posts.

Many themes (like the Virtue Theme on the You Show) give you an option to display posts from a category, rather than just the newest. I helped Franzi today flip hers using the stick Twenty Fourteen Theme; there is an option in the Customizer to put posts tagged “featured” in the front magazine style layout.

For themes that do not provide this, I have gone the route of customizing the WordPress Loop query used on the front page. A non hacking route is the Category Excluder from Theme Customizer plugin which lets you choose which categories not to display on the front page.

This capability becomes very useful on Feed WordPress type aggregation hubs because the inflow of posts is so high (hopefully) that a river of new posts is not useful.

My strategy is to recommend that people who are admins on the site do some curating-by editing aggregated posts to add a category (or tag), they can create a set of “featured” posts (viewable via the Category Archive view). I was never able to get the Connected Courses folks to grasp this idea; maybe no one wanted that responsibility.

I did try using a rating plugin on the ETMOOC hub that enabled a “highest rated” view but not too many people voted.

As a site admin, it helps to do this via a category process because it forces you to regularly review incoming stuff. I set it up on the You Show site, we have a category called “Highlight Reel” we can add to posts:

highlight-reel

But the process for getting to the posts to add the category was.. tedious. In an archive view, there is no way to edit that post, and because the links in the syndication hub go out to the site, it is not an option to view the post, and then click the “Edit” button in the admin bar.

Some themes add an “edit” link in the templates so you can do this, but Virtue does not. It’s a pretty easy thing to add, if you can find the write template file (this varies from theme to theme, in Virtue, it was in /templates/content). The thing you want to add is the wordpress function edit_post_link. There are options you can use on that function to add spans and or css classes, but at it’s simplest, somewhere in the loop where it is spitting out content for each post, add something like:

<?php edit_post_link('Edit Post')?>

What this does is add an “edit” link next to each post that can only be seen by users that are logged in with post editing privileges (Editor, Admin, etc). Visitors to the site will not see them.

These helps some, because if I see a post on the flow I’d like to feature, I just:

  1. Click the Edit Post link
  2. In the editor, click the category to add
  3. Update the post

    It’s not bad, but still seems 3 steps when all we need to do is to add a category. So I hacked something in.

    I will need a way to send from the clicked link a variable that identifies the post ID number I am updating. In my (child) theme functions.php, I do need a function that allows WordPress to understand extra URL parameters. For my site, I am using ones already created for the signup form:

    /* ----- add allowable url parameter for urls */
    add_filter('query_vars', 'youshow_parameter_queryvars' );
    
    function youshow_parameter_queryvars( $qvars )
    
    // allow parameters to be passed in wordpress query strings
    {
    	$qvars[] = 'pid';	// when we need to pass a post id
    	return $qvars;	
    }    
    

    This means I can send to a WordPress URL something like:

    http://www.mysite.org/feature-this/?pid=23

    And my custom template for this page named Feature This has some logic it can act on.

    Next, I made a function that can put the link to mark a post as featured, and make it so only people logged in with editing privileges can see (and click) on it.

    function get_highlight_post_link ( $post_id, $toolslug = 'feature-this' ) {
    
    	// only for editors and above 
    	if ( current_user_can('publish_pages') ) {
    		return (' [<a href="' . get_site_url() . '/' . $toolslug . '/?c=' . $post_id . '" target="_blank">Feature This</a>]');
    	}
    }
    

    I send the function get_highlight_post_link() a value for the post I want to affect. By default, the link will be to a page on my site with a url / slug name of feature-this. And it opens in a new window so I don’t lose my place

    This is solely so I can add this to my templates. By making it a function, I can use it more than one template. In my theme, I find the part of the code that echoes the meta data below a post, and add in:

    ... (meta data theme stuff like date, comments, categories)
    < ?php edit_post_link('Edit Post')?> 
    < ?php echo get_highlight_post_link( $post->ID )?>
    

    Now… (if anyone is still with me). I create a page that has the slug name (url) of feature-this which means if I create and upload a new theme template named page-feature-this I can put in stuff that only is used on the one page.

    The way to do this is to copy the basic page.php template for your theme, and rename it page-feature-this. Put this code at the top:

    < ?php
    // get the proper category ID, yuck hard coded. Shoot me.
    $def_category_name = 'Featured';
    
    // we need the category's ID
    $highlight_category_id = get_cat_ID( $def_category_name );
    
    // get the value of parameter that represents the id of the post to change, 
    //    if not present, set value to -1
    $post_id =  (isset($wp_query->query_vars['pid'])) ? $wp_query->query_vars['pid'] : -1;
    
    // set up array to update post
    $w_information = array(
    	'ID' => $post_id,
    	'post_category' => array( $highlight_category_id )		
    );
    
    // update the post, value is 0 if it borked
    $da_post = wp_update_post( $w_information );
    ?>
    

    This all happens before the page loads. Farther done in the template, after where it spits out the contents for the page (which can be anything, its only for admins) add right after

      	<h3>Processing...</h3>
      	
      	< ?php 
      		if ( $post_id == -1)  {
      			echo "<p>Uh oh. No post id found. Bad link?";
      		} elseif (!$da_post) {
      			echo "<p>Egads. Something bad happened. Unable to update post.</p>";
      		} else {
      			echo '<p>Eureka! We added <strong><a href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></strong> to the <a href="' . get_category_link( $highlight_category_id ) . '">' . $def_category_name . '</a> Category. Yipppie!';
      		}
      		?>	   
    	< ?php endwhile; ?>
    

    With this in place, I can add a post from any archive view listing to our "Highlight Reel" category, by clicking the "Highlight This" link (my names are different from the example code above)

    Admin's only have access to these tool links
    Admin's only have access to these tool links

    It not only makes it simple for me, I can give anyone I want to push things into this curating role an Editor role, and then can log in and mark posts to be featured.


    Top feature image credits : cc licensed (BY-NC-SA) flickr photo by Neetesh Gupta (neeteshg): http://flickr.com/photos/neetesh/6766075885

The post "One Click Featuring in WordPress Sites" was originally thawed from a previous ice age and melted at CogDogBlog (http://cogdogblog.com/2015/02/one-click-featuring/) on February 5, 2015.

1 Comment

Leave a Comment

All fields are required. Your email address will not be published.