Category: HOWTOs

Category Feeds

A number of my WordPress clients recently have been wishing for a way to offer multiple feeds with specific posts in them completely unaware that this is actually very easy to do with WordPress without any modifications.

You can simply accomplish specific content feeds by using category feeds. For example. If you have a WordPresssports site with 3 categories: Football, Baseball, Hockey and you want to offer a feed specific to each category – all you would need to do is to add “/feed/” to the end of the category URL.

Example: Your category feed is: http://www.sports.com/category/football. For this site – your category feed for football would be: http://www.sports.com/category/football/feed.

Advertising multiple feeds for your site can be very attractive for a few reasons:

  1. Better Focus You can offer subject specific feeds since not all people like to read about everything. (ex. A reader likes your site for your coverage on a certain subject matter – but does not really care or come back for posts about anything else. Ex. With category feeds – you can really let the user/reader decide what they want content to read about on your site.
  2. More Options = Happy Readers People like options. You would be surprised how many people get excited to pick and choose what they want to subscribe to vs. getting everything all at once. If they are forced to get all the content and only 15% of your content pertains to something they do not care about – they are likely to not subscribe at all or after awhile – stop reading your feed. If you offer some choice – people are more likely to subscribe because they will only get the content that they care about.
  3. Featured Posts If you want to offer a special feed for “featured” posts – all you need to do is make certain posts in a category called “Featured” and you then offer a hand selected featured posts feed to your readers.

If you want to list all your categories and their feed links, you can simply add this into your WordPress theme:

<ul>

</ul>

View All Options for WordPress

Ever need to view all options for all your plugins (and standard WordPress options like home URL, etc)?
You can view every option available (and edit most) by going to: http://www.yoursiteurl.com/wp-admin/options.php (assuming WordPress is in the root folder).

So now if you need to look at options, make changes, or see a particular value – you can do so on one page.

Conditionally Show Only On Home Page (Front Page)

There a are two functions that are used quite a bit to conditionally show content on the very front page (home page or page 1 of your blog). First – we had the function is_home(), but in WordPress version 2.5 – a new function was introduced: is_front_page().

You might think both would conditionally only display content on the home page (front page, page 1 of your blog) – but you actually need to use the following code to accomplish showing something ONLY on the front page of your paged blog:


<p>Show this text only on the home page</p>

So – if you want to easily show something on what I would consider the front page – use the code above to successfully achieve that. (This is particularly helpful if you have ads that run speficically on the home page and others that are ROS (run of site).

Further reading:

Get Top Parent Category (WordPress)

There are many times when you need to show or get the top most (root) parent category in WordPress – regardless of how many subcategories you might be deep. I have used this logic for page navigation (highlight the top parent tab) – as well as within some custom loops/sidebar code.

They way to do this:

// get parent category slug
$parentCatList = get_category_parents($cat,false,',');
$parentCatListArray = split(",",$parentCatList);
$topParentName = $parentCatListArray[0];
$sdacReplace = array(" " => "-", "(" => "", ")" => "");
$topParent = strtolower(strtr($topParentName,$sdacReplace));	

To test this you can simply put it in your header and echo out $topParent and you will see the “slug” of the category.
If you want to see the category name and not necessarily the slug – you can simply echo $topParentName.

Show One WordPress Post

There is a great function you might be aware of that allows you to get one WordPress post and display it anywhere you would like (header, sidebar, home page, etc).

To show only one post, use the function get_post.

Example:

post_title;
$sdac_content = $show_post_id-&gt;post_content;
?&gt;
<h2></h2>
 

The code above will show the title and content of the post with the post ID of 10. If you are not sure what your post ID is, go to the manage screen in the WP-Admin, and hover over the post title. In your browser status bar, you will see the URL – and the post ID is the number at the end of the URL.

Remove Initial Flicker With Smooth Gallery

I recently created a site (in beta testing now) with Smooth Gallery and the client loved it.

The Problem:
The only issue was that upon the initial page load – all items in the gallery would flicker for a second or two while the first image loaded – causing this to not look professional at all.

The Solution:

  1. HTML: I took the example code:
    <div>
    
      <div class="imageElement" id="element">
          <h3>Item 1 Title</h3>
          <p>Item 1 Description</p>
          <a href="#" title="open image" class="open"></a>
          <img src="images/brugges2006/1.jpg" class="full" />
          <img src="images/brugges2006/1-mini.jpg" class="thumbnail" />
       </div>
     
     </div>
    

    I then added an ID to each div (id=”element1″) so that each div had a class of “imageElement” and a unique ID (element1, element2, etc).

  2. CSS: Now that I had IDs to style, I added the following to my style sheet:
    #element2 {display: none;}
    

By adding the 2 bits of code mentioned below, I was able to initially hide the content in the second div so that only the content in the first div appeared on page load. Once the script started running, it then changed the display from none to block automatically. Problem solved.

ShareThis Button Cut Off Fix

I have seen a lot of sites using the ShareThis button (including a few of mine) where the button in Safari was getting cut off (clipped) at the bottom. If this is happening to you – there is a quickfix. Add this line of CSS to your stylesheet and your button will no longer be cut off.

.stbutton {display:block;height:16px;}

Order Blogroll Links Easily Without a Plugin

For a no-nonsense way to set the order of your Blogroll links within WordPress, place a numeric value in either the description or notes field then set up the wp_list_bookmarks function to order by that value. Make sure numbers that are < 10 are put in as two digits (01, 02, 03). This is not ideal, but it is quick and easy…and it works.

Once you added in the links to the Blogroll admin, use the following function: wp_list_bookmarks to display your links on your site. The following example will list all links and order them by the value in the description field. The output will not have "blogroll" nor the link category headings. For more information, check out the wp_list_bookmarks documentation.


XOOPS Login Issue: 2.0.17 and 2.0.18

After updating XOOPS to 2.0.17 a few months back, I ran into a problem with certain users not able to see group specific blocks after updating. The users would authenticate, but then not see any content that was “member only”. I was hopeful this would have been resolved with 2.0.18 but it still remains an issue. The problem:

The solution:
In your XOOPS directory: /kernel/session.php

change:
var $enableRegenerateId = true;
to:
var $enableRegenerateId = false;

(Original fix documentation for 2.0.17: http://www.xoops.org/modules/newbb/viewtopic.php?topic_id=62411&forum=2&post_id=281576

Upgrade Google Analytic Tracker Code

If you use Google Analytics on your web site, you should update your tracker code that is placed in your code. The new tracker is faster, and offers added tracking functionality (See Google’s announcement)

New Code: (put your tracker ID in where you see the X’s)



var pageTracker=_gat._getTracker('UA-XXXXXX-X');
pageTracker._initData();
pageTracker._trackPageview();

While you are updating your code, you might also want to consider moving this and any other javascript to the bottom of your web site for improved performance.