Solving Not Found Issues with Atahualpa — Introduction

Of the three free WordPress themes I recently reviewed, Atahualpa is most certainly my favourite. But that’s not to say that Atahualpa is perfect. I’ve still had to overcome my fair bit of challenges while working with Atahualpa. I’m particularly proud of my php-free workaround for solving Not Found issues with Atahualpa, so here’s what I did in the hopes it will be helpful to others.

The Problem

The main problem with the way Atahualpa displays Not Found pages is that there is no distinction between a 404 and a search with no results. They both look the same, but they don’t act the same. It’s confusing and moreover, it can cause layout and design inconsistencies on your website.

Advertisement:
The first step in solving Not Found issues with Atahualpa is to identify what, exactly, is Not Found. There are two situations in which something could return a Not Found page. In scenario 1, a user types or clicks an invalid URL and lands on a 404 Not Found page. In scenario 2, a user performs a site search for which results are Not Found. Simple, right?

Yet, to me, it seems that Atahualpa’s handling of Not Found issues tries to keep things a little too simple.

Recall from the WordPress Template Hierarchy that when a site search is performed, search.php is the first template called to display the search results. If no search.php file exists, then index.php is called. Similarly, 404.php is the first file called to display a 404 Not Found page, but if none exists, then once again, index.php is used.

But as it turns out, Atahualpa doesn’t include either a search.php file or a 404.php file, so both types of Not Found scenarios rely on index.php.

Now there’s nothing wrong per se with Atahualpa’s treatment of Not Found issues, but the potential exists for this situation to cause problems, namely user confusion and design inconsistencies. The primary reason for this potential to wreak havoc comes from the use of one of my favourite Atahualpa features: sidebar control.

Atahualpa has four sidebars in addition to a centre column, two on each side. Each sidebar can be styled separately, and the display of each can be controlled for different types of pages site-wide. For example, you can choose to activate all four sidebars on the 404 Not Found page, but only display the outer-left sidebar (or any sidebar combination) on the search results page.

Remember that Atahualpa uses the same template, index.php, to display search results and 404s. If there are any search results, the template follows the same pattern as for any other posts archive page — respecting the sidebar selection, of course. And if no content is found, Atahualpa delivers the same Not Found message.

Yet, when a site search doesn’t return any results, at least two things happen to distinguish it from a true 404 (nonexistent content). First, the page title is different. A true 404 returns a page titled “Not Found.” A site search without any results returns a page titled “Search for [term].” Second, the sidebar selection is respected for the 404 versus the search result. Depending on your layout, one of the two Not Found pages may end up looking really awkward.

That’s what happened to me at the former JourNiackery site, which is what prompted me to investigate the matter further and try my hand at solving Not Found issues with Atahualpa. I wasn’t using any sidebars on the site, yet I wanted to use some on both types of Not Found pages, one on each side of the page. This was important to me because I was trying to provide my site users with a more useful Not Found page, one that would help them find what they were looking for.

The problem was that if I turned on sidebars for search results, they would be displayed no matter what. I really didn’t want the sidebars on the search results page when results were found since it looked so weird having post excerpts in the centre column between mostly empty sidebars, instead of displaying full-width excerpts. I only wanted the sidebars on Not Found pages, but turning on sidebars on only the 404 page didn’t display them on Not Found search results.

The Fix for Solving Not Found Issues with Atahualpa

Stuck with this dilemma, I searched the Atahualpa support forum and eventually found that I could create my own search.php file by copying index.php, making the desired changes in the new file, and uploading the new file to my theme folders. For the most part it was easy, thanks to the good advice from the forum, but one thing stumped me: I don’t know any php! How would I make the changes to the new file?

Advertisement: Memories of a Carnivore: Adventures in Eating Ethically, by Julie Dupuis. Raw. Irreverant. Humorous. Fragmented. Download now for only $1.99.
Well, I can read enough php to find the part that was relevant to my planned search.php file. But would I ever be able to find code snippets that did everything I wanted? I didn’t want to have to ask/hire someone to write the code for me — I’m really independent and enjoy the challenge of solving a problem. And trust me, solving Not Found issues with Atahualpa was a good challenge! So I started thinking outside the box.

Or rather, I started wishing outside the php code. It struck me that I could insert a custom widget area or two and just build my content from within an Enhanced Text Widget (see Under Construction: Most Useful Plugins (Part 2) to find out why I love this plugin). Once I figured that out, I grew bold and decided to add a custom widget area to the Not Found section of index.php as well. And it’s so easy to create a custom widget area. Atahualpa describes the process step-by-step in its theme options.

Advertisement:
So now I’ve successfully finished solving Not Found issues with Atahualpa, I’ve got a unique 404 Not Found page that’s helpful to users who have clicked or typed an invalid URL, and I’ve got a unique and helpful Not Found page for search results as well. I’m thrilled that things are working exactly the way I want.

First Steps to Solving Not Found Issues with Atahualpa

Creating a Custom Search Template: search.php

Here’s a simple step-by-step guide to solving Not Found issues with Atahualpa without having to write any custom php code of your own, but while still retaining control and creativity of your Not Found pages. You will have to read through some php code to find the relevant sections, then copy and paste some of that php code, but it shouldn’t get any harder than that!

Announcement: Like what you've been reading? Say Cheers with a cup of tea!
  1. From your WordPress Dashboard, go to Appearance → Editor.
  2. Open the index.php file, called Main Index Template, then copy and paste it into Notepad, Text Cleanup, or any other program that generates a .txt file extension. Don’t use MS Word as it will add background code to your file.
  3. Now it’s time to edit the code. You’ll want to keep most of the file and head straight to the bottom. Find this:
    <?php /* END of: If there are any posts */
    else : /* If there are no posts: */ ?>
    
    <?php // Deactivated since 3.6.5
    #include 'bfa://content_not_found';
    // Uses the following static code instead: ?>

    The section below that is what you’ll want to change. Delete this:

    <h2><?php _e('Not Found','atahualpa'); ?></h2>
    <p><?php _e("Sorry, but you are looking for something that isn't here.","atahualpa"); ?></p>

    Now you can insert whatever you want to replace that. I chose to repeat some of the elements from the /* If there are any posts: */ section, such as useful custom widget areas I’d previously registered using the Atahualpa theme options. Plus I created a custom widget area of my own. Here is code like I am using, which you can use to create your own search.php file:

        <?php bfa_widget_area('name=Not Found Center Top Widget Area'); ?>
    
    	<?php bfa_widget_area('name=No Search Results Widget Area'); ?>
    
    	<?php // Deactivated since 3.6.5
    	# include 'bfa://content_below_loop';
    	// Uses the following static code instead: ?>
    
        <?php bfa_widget_area('name=Not Found Center Bottom Widget Area'); ?>

    This will create three widget areas in the centre column, one above the other.

    If you have already registered widget areas of your own for your centre column via Appearance → Atahualpa Theme Options → Style & Edit Center Column and you would like to use the same widgets in the Centre Top and Centre Bottom widget areas on both the Search Results and Search Results Not Found pages, then replace the Center Top and Center Bottom widget areas with these instead:

        <?php  if ($bfa_ata['widget_center_top'] <> '') {
              echo bfa_parse_widget_areas($bfa_ata['widget_center_top']);
    	} ?>

    AND

    	<?php // Deactivated since 3.6.5
    	# include 'bfa://content_below_loop';
    	// Uses the following static code instead: ?>
    
        <?php if ($bfa_ata['widget_center_bottom'] <> '') {
              echo bfa_parse_widget_areas($bfa_ata['widget_center_bottom']);
        } ?>

    To create your own custom No Search Results widget area (with multiple cells, for instance), follow the instructions at Appearance → Atahualpa Theme Options → Add New Widget Areas, then place your code in the search.php template you are creating.

    Finally, make sure that your file still has this at the end:

    <?php endif; /* END of: If there are no posts */ ?>
    
    <?php get_footer(); ?>

    Search Results Bonus Tip

    You can add a custom widget area to the section of your file that displays search results as well, if you’d like to use different Centre Top content depending on the situation. To do so, find this in your search.php file:

    <?php /* If there are any posts: */
    if (have_posts()) : $bfa_ata_postcount = 0; /* Postcount needed for option "XX first posts full posts, rest excerpts" */ ?>
    
        <?php  if ($bfa_ata['widget_center_top'] <> '') {
              echo bfa_parse_widget_areas($bfa_ata['widget_center_top']);
    	} ?>

    Add your new custom widget area below that. Here’s a code you can use which will create a widget area that spans the full-width of the centre column:

    	<?php bfa_widget_area('name=Search Results Custom Widget Area'); ?>
  4. Save your new file as “search.php” and make sure to include the quotation marks. Once you close the file, it will convert to a valid php file. You may need to rename it and delete the quotation marks, but I didn’t need to. (Thanks to the article 404 Custom Error Page for WordPress for this awesome tip.)
  5. Now access your cpanel’s file manager via your webhost account (I’m currently with Bluehost (Affiliate Disclosure), for example). Follow the path public_html → “Your Website Name” → wp-content → themes → Atahualpa and upload your new file.
  6. Reload your website and access your Widgets to place content in your new Not Found search results widget areas!

You can now be as creative as you want while being as helpful to your website visitors as you know they deserve, all without having to come up with any custom php code. You’re halfway through solving Not Found issues with Atahualpa!

The Final Touch to Solving Not Found Issues with Atahualpa

Creating Custom 404 Not Found Content Without Creating a Custom 404 Template: index.php

Now that you’ve found the index.php file, you can continue solving Not Found issues with Atahualpa. Edit the file directly from Appearance → Editor and delete the same text as you did before to now customise your new 404 Not Found page. Why bother creating a whole other 404.php file when you can just insert a widget area and be done with it? This time around, however, you’ve got a few options:

  • You can keep the part wrapped in h2 tags and just delete the message. Change the Not Found title to something else if you want. Just make sure you don’t delete the single quotes around it.
  • You can keep it all and add your widget area below the message. Edit the message if you want. Again, be sure to retain the single quotes.
  • You can delete it all and start from scratch with your custom widget area.

I chose to change the h2 to h1 and rename the page to something a little more fun. I created a new custom widget area and added the same code for the Center Bottom custom widget area that I previously used in my search.php template.

Remember to do the same. That is, use the same code for the Center Bottom widget area in both search.php and index.php.

Here’s what I’ve done — feel free to use it in your own template if you like:

<center><h1><?php _e('Oops!','atahualpa'); ?></h1></center>

<?php bfa_widget_area('name=Not Found 404 Widget Area&cells=3'); ?>

	<?php // Deactivated since 3.6.5
	# include 'bfa://content_below_loop';
	// Uses the following static code instead: ?>

    <?php if ($bfa_ata['widget_center_bottom'] <> '') {
          echo bfa_parse_widget_areas($bfa_ata['widget_center_bottom']);
    } ?>

Once I saved the file, I just added content to the new Not Found 404 custom widget area, which is actually three separate widget areas that align horizontally. Remove &cells=3 to make it just one full-width widget area, or change the 3 to any number of cells you want.

No more boring Not Found messages, and hopefully, increased visitor satisfaction (smiley face).

Info and Resources for Solving Not Found Issues with Atahualpa

A note of caution to anyone who wants to implement these tactics for solving Not Found issues with Atahualpa. If you’re not using a child theme, you will lose any changes you make, both via the Editor and the cpanel, during the next theme update, so make sure to keep track of all your modifications and make backups of the php files you create.

I don’t use a child theme since I have made very few php changes. I keep track of them in a .txt file and it only takes me a few minutes to apply them each time there’s a new version of the theme. If I had many customizations, I would definitely be using a child theme to save time and dodge mistakes.

To avoid losing my search.php file when the theme updates, I created a new folder from my host’s file manager where I keep a copy of the file. I can just copy it back over to the Atahualpa theme files whenever there’s an update, so that really couldn’t be simpler. And just in case something happens to that copy, I’ve made a .txt backup as well.

If you’re looking for extra help solving Not Found issues with Atahualpa, I found these forum and codex posts very informative:

Have you figured out a different way of solving Not Found issues with Atahualpa? If so, I’d love to hear about it! You can share your wisdom in the comments section below.

If this information about solving Not Found issues with Atahualpa has been useful to you, please let me know by leaving a comment and perhaps even sharing links to your own modified Not Found pages (smiley face).

Update: For similar help with the Parabola theme, check out Improving Parabola: 8 Simple Theme Tweaks. It’s got a section on how to create better Not Found pages.