Category Archives: Coding

How to Minimize Duplicate Content in WordPress Blog

After reading this post at Google’s Webmaster Group, I was inspired to find out how to stop displaying full content on pages where posts were listed in categories, archives, etc. I am not so concerned about duplicate content as much as I don’t like for people to find a result in a category page but they have to look around the page to find it, or the post got moved to another page in the category and thus can’t find what they were looking for.

I didn’t know how to go about doing it so I searched. This page, Showing full posts on homepage, but snippets elsewhere, was a good start.

In short, the key is to edit the theme’s archive.php:

Change:

<?php the_content(); ?>

to:

<?php the_excerpt() ?>

A while back, I had copied the archive.php from the Default theme for another purpose, because Ocadia didn’t have its own version of the file. I ended up not using the file for anything important so I didn’t modify it much. Once I edited it to show snippets, or excerpts, on category and archive pages I noticed that it didn’t look like the homepage listings. For consistency, I copied the code between the divs for <div class="post"> in the theme’s index.php. With that change, pages for categories and archives no longer showed the posts in their entirety.

However, posts that were listed on “previous pages”, such as the one linked to at the bottom of the home page, continued to be a source of duplicate content. In the ocadia index.php, the code for search page is written to show excerpts. What I did was add a condition so that pages showed excerpts, too, like this:

<?php if (is_search() || is_paged()) { ?>

<?php the_excerpt() ?>

Now, if you go to the deeper pages of the index, category, etc, it shows post excerpts.

I also read recommendations to do the same to the home page. When I made the change to the home page, I did not find it aesthetically pleasing. The excerpted posts on the home page of the blog made it look like a splog that had scraped the content–not a good first impression for visitors. This was a situation where user experience trumped search engine optimization.

I just made these changes tonight. Time will tell if this will help or not.

Added Image Scroller Based on iTunes

rphMedia over at the Coppermine forums has offered a mod called Image Scroller – based on iTunes. It looks so cool that I couldn’t help but implementing it at my Take Thu gallery and my blog (at the bottom of the blog’s homepage).

For those who want an includable version of flow.htm, create a file in the include folder called flow.inc.php:
Continue reading

Using Search Everywhere Plugin to Search Jerome Keyword Tags

I installed the Search Everywhere Plugin in the hopes of enabling WordPress search to find posts that have been tagged with Jerome Keywords Plugin. Alas, it didn’t have that capability built-in, nor could I find an available solution, so I tweaked the Search Everywhere code to search tags for results. I based the code modifications on the meta search function. There were four places where I edited the code. Since I’m currently too lazy to provide the instructions, I’ll provide the file as an attachment.

To test that my code works, here’s a search where the query does not appear anywhere else but the tag. It points to this post, but I didn’t want to apply it to an unrelated post since it could cause confusion. You can also confirm that the query does not show up anywhere in this post. Also, to really confirm that the query worked due to the tag and not because of it showing in the url of a post, I tested it on another post. I removed the tag on that other post to avoid confusion.

WordPress doesn’t allow uploading .php files so I had to append .txt to the filename. Just remove .txt, rename it so that it ends in .php, and install the plugin as usual.

Download file: Search Everywhere Plugin

Google AJAX Search Results in WordPress

Not even a day had passed since I figured out How to Integrate Google Custom Search Engine Results into WordPress Blog Template and I figured another way to integrate search results into WordPress.

As described at the site, “Google AJAX Search API lets you put Google Search in your web pages with JavaScript.”

One of the drawbacks to the earlier method was that the results were in an iframe, so it was less integrated in the look of the site. Another thing I wanted was to be able to switch from searching my blog to more general search.

The second method using Ajax allows for customizing css of the search results, and it has tab functionality to show different types of results.

Someone had already implemented Ajax Search in Blogger. I used the provided template to come up with a slimmed-down version of the code to put into my WordPress blog.

At first, I was going to put the search results in a separate page. But I didn’t know how to do the search form for it, so I did what the ajax blogger did and put it right on the page where the search is executed. You can view the source if you want the search code. I put the search form in a widget in the sidebar.

I wrote the code so that the “More results” link goes to my template but it’s not working for some reason. I saw in an example where it worked, though. It’s a new feature so hopefully it’s just a temporary issue. Update: It turned out it was because I didn’t include the hl parameter, which was required. Oops.

Another thing I wanted to do was take advantage of the new feature, “Linked Custom Search Engines” to show results that were not only from my blog, but from sites I link to. This would have greater focus than a general web search, and would show results from related sites when mine doesn’t have the results. However, the results aren’t what I had expected so I need to do some more research to refine the custom search engine.

Update: I won’t be dropping the other search page because it comes in handy as a template for search results. I can use the Ajax search for results on the page, but for additional results, I have to fall back on the non-Ajax search.

Update: After investing a lot of time to ensure that this worked throughout my blog, I found that there is an Ajax search plugin. I installed it to see if it would meet my needs. It’s definitely convenient to have a plugin, but it doesn’t support CSE, for example. However, for someone who doesn’t already have this functionality, the plugin is a great option.

How to Integrate Google Custom Search Engine Results into WordPress Blog Template

I was checking out the control panel for my blog’s Google Custom Search Engine and saw something under the Code tab that I hadn’t noticed before: Search box and search results code for your website

I was intrigued at the thought of having the search results show up with my blog’s theme. After completing my search page, I thought I’d share how to do it.

First, create a new page in the theme’s folder called _search.php and upload it with the following content:
Continue reading