• MyOxy
  • Offices & Services
  • Alumni
  • Newsroom
  • Calendars

Occidental College

Our StoryAdmission & AidAcademicsLife at OxyLos AngelesOxy VoicesGivingGo Tigers!

Center for Digital Learning & Research

  • Center for Digital Learning & Research
  • Blog
  • Improving Wordpress Search Function: Plugin Fun

Improving Wordpress Search Function: Plugin Fun

April 11, 2012

I recently decided to start sharing my reflections on my day-to-day as a postdoc in Digital Scholarship at Oxy. I welcome feedback on my work because at times I feel as if much of our work could go unnoticed in a world so dominated by conventional notions of research and learning. Anything alternative to traditional research (i.e. publishing) and teaching (within the curriculum) -- or labeled as #altac -- could get lost in the mix. I'm cross-posting from my personal blog.

One of the faculty projects associated with the CDLR is Lisa Wade's Sociological Images, one of the most visible and influential public sociology sites in the blogosphere. To follow up on our last meeting with Lisa, I scoped out the use of a plugin as a possible solution to improve the search function on a Wordpress site. Specifically I played with a Wordpress search plugin called Relevansii because of its high ratings and robust documentation community. On the backend, the admin can configure the setting of the search to enable a specific combination of AND/OR queries. For instance, it could run a AND query first and if no results return, it would run an OR search. It does a good job with phrase search with quotes (e.g. "hillbilly music"). And it has fuzzy matching (matching partial words if complete words don't match).

With a bit of script tweaking, with the help from Relevansii's documentation page, I got the plugin to work pretty well on my course blog for CSP27 Race and Gender in Pop Music. I have it set so that it searches the post content, title, tags, and categories. I gave more weight to post titles than  tags and comments. Based on the configured algorithm, the search gives a "relevance score" which determines the order of the research results. I also got the result page to highlight the search terms in excerpts and indicate the number of hits. To display the number of search results, I tweaked the one-line code that I found on the documentation page and inserted it into the line scripted to return the search term in the header section of the code in search.php. [The WP theme that I use for the blog is Twentyeleven.]

<?php printf( __( $wp_query->found_posts . ' Search Results for: %s', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?>

One could further tweak the look of the search results; for instance, changing the length of the excerpts, font style of the search terms, etc. What's cool about this plugin is that one could do a category/tag filter in the search. This restricts the search to process only the documents labeled with a selected category/tag term [similar to the search on commercial sites like newegg.com or Amazon]. I tweaked the standard searchform.php using the example code snippet that I found on the documentation page. This is the bit of code that I ended using:

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
 <label for="s"><?php _e( 'Search', 'twentyeleven' ); ?></label>
 <input type="text" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
 <?php wp_dropdown_categories(array('show_option_all' => 'All categories'));
     /*this is code snippet from relevansii for category filter */
  ?>
 <input type="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
</form>

On my blog, I have it set up so that the search results can be filtered by the existing post categories (namely, reading responses, assignment, etc). In the case of Sociological Images, it would be useful to restrict the search using the existing tags on the site. Alternatively, one could further refine the structure of the posts by assigning them with higher-level category terms. Give it a shot and play around: http://cdlrsandbox.org/wordpress/racegenderpop

Center for Digital Learning + Research

  • Blog
    • Hight Tech Happy Hour focused on Classroom Design
    • Mellon Digital Scholarship Speaker Series: Mark Sample
    • Making songs to learn about songs: mobile music-making with iPad
    • Mellon Digital Scholarship Speaker: Dhiraj Murthy
    • Introducing Décalages
    • Inspiring return to Visions of Students today
    • Moodle 2.0 Beta Release Coming Soon
    • Selected OA Projects
    • Save the dates for a series of CDLR events
    • Patricia Aufderheide to speak at Occidental
    • Networks and Enclaves conference
    • NEH/ODH SUG Lightening Rounds
    • NLM Announces Mobile MedlinePlus
    • On Autoethnographies and Acafandom
    • Doing Digital Scholarship
    • Improving Wordpress Search Function: Plugin Fun
    • If you are not a programmer...
    • Back at it again: Tinkering with Maps
    • Call for 2012 Mellon Summer Digital Scholarship Institute
    • Alternate Careers for Humanities Ph.D.s
    • Alex Juhasz to speak at Occidental
    • A site reviewing the intersection of literature and technology
    • CDLR Studio Sessions
    • Citing Tweets?!
    • Digital Media and Learning Conference
    • Digital Scholarship Symposium @ Occidental College
    • Digital Higher Ed project
    • DH SoCal
    • Copyright Law Chart
    • A multimodal musical analysis: visualizing diaspora
    • 54,748 OxyScholar Downloads to Date
    • Generation Lost or Generation Found?
    • Fair Use
    • How to offer training workshops to busy faculty?
    • Ever tried unplugging yourself for 24 hours?
    • "The Mixtape Project" Assignment: learning through critical making
    • EDUCASE Learning Initative to Stream Live in the CDLR
    • ST Projects
    • Upcoming Event: iPad Studio Session on Garage Band
    • Upcoming Event: Studio Session: Arduino 101
    • Yola: A Free Website Hosting Alternative
    • Webinars of interest
    • Testing to learn
    • The Death and Life of Digital Scholarship Centers
    • Upcoming Event: iPad Studio Session - iMovie
  • About
  • People
  • Projects
  • Email: [cdlr@oxy.edu]
Tweet

Occidental College

  • For Parents
  • Employment
  • Contact Us
  • Maps & Directions

1600 Campus Road Los Angeles, California 90041