Last week I wrote an overview of the WordPress plugin, Twitter Tools. In the article, I discussed the option in Twitter Tools to send all of the your daily tweets to WordPress as a digest post. While I like the idea of using WordPress to archive twitter, I don’t want a daily post of my tweets listed on the front page or in the archives as I consider it to be content padding and really boring for most readers. Since you can assign a category to the daily post digest, I researched the wordpress code needed to exclude categories from the front page and from archives and then spent part of this morning testing and implementing it on this site.
This ended up being more complicated than I anticipated. The template used on this site references the categories in numerous locations and I had to add code and make changes to this template in the following locations; front page, archives page, category list in sidebar, list of recent posts in sidebar, and list of recent posts in the footer. Below I will outline the steps and the code needed to send your daily twitter postings to your WordPress blog but to not have them displayed.
- Create a new WordPress category that will only be used for the digest posts. I named mine ‘digest’. Note the number of the category as you will need it in the exclude code.
- Go to Settings > Twitter Tools and set that category and the user. I am the only user of this blog so I didn’t have to change that setting.
- Set Create a daily digest blog post from your tweets? to Yes. I temporarily changed Create a tweet when you post in your blog? to No because I didn’t know if the digest post would be sent to Twitter even if it was excluded. I still need to test this.
- Please note that I can still not display code in a post without that code being executed even when I place it between the code tags. So all code snippets need “< ?" and the beginning and "? >” at the end. Sorry about that and if anyone has any ideas about this, I would appreciate a solution. On the main index page add
if (in_category(’23’)) continue;
if (have_posts()) :
while (have_posts()) : the_post();
This will exclude the digest post from the front page of your site. Make sure to change ’23’ to the number of your category.
- Add the same piece of code to your archives page, if you don’t want the twitter digest displayed on that page. I contemplated leaving it available in the archives but decided to be consistent and remove all instances of the digest and to only have it available to me as a backup. If you have other archive type pages, such as categories, you will want to add the code there as well.
I then needed to find a way to exclude the digest post from the two instances of Recent Posts. I use a WordPress query to pull recent posts to the sidebar. If you are using a plugin and displaying Recent Posts as a sidebar widget, I am not sure how to implement the exclusion.
php $recent = new WP_Query(“showposts=8&cat=-23”); while($recent->have_posts()) : $recent->the_post();
I added &cat=-23 to remove the category of the digest posts from the list of recent posts. Again, I needed to do this in the sidebar and the footer. Make sure to use the minus sign in from of the category number.
- Finally, I need to edit the Category List in the sidebar so that the Digest category was not displayed. This made me remember why I don’t like using widgets, even when it is easier to do so. My list of categories was displayed via a widget but since I couldn’t edit the code for that, I entered the category code manually.
Again, the excludes the category from the list via the category number. &title_li= is used to supress the category heading. This is not necessary for category exclusion but was something I needed to do to maintain consistent styling.
This is what a daily twitter digest post would like if you weren’t hiding it. Of course, it would have your own blog style.
There are a couple of things that I’m not sure of and still need to test.
- Will the digest post show up in my RSS feed even though it has been excluded from being displayed?
- If I turn on the posting to twitter with each new post option in Twitter Tools, will a notification be sent to Twitter when there is a new digest post?
- What time of day will the digest post arrive? The one that I took the screenshot of arrived almost immediately after I turned on the feature and was a digest of my twitter activity from yesterday.
I am going to continue testing this. I would like a twitter archive, even though my archive will only start from yesterday and won’t contain 900+ tweets. But there does seem like a lot of parts to this that need to work correctly and I’m not sure if it is something that is worth maintaining. I did, however, learn how to exclude categories in WordPress pages and that must surely have many practical uses.
- Template Tags/wp list categories – from the WordPress Codex
- Super Loop: Exclude Specific Categories and Display any Number of Posts – from Perishable Press