Tag Archives: Plugin

WordPress breadcrumbs without plugin

Open your theme functions.php and add the following code:

function xsimu_breadcrumb() {
        echo ' <ul id="breadcrumbs">';
    if (!is_home()) {
        echo '<li> <a href="';
        echo get_option('home');
        echo '">';
        echo 'Home';
        echo "</a><span class='separator'>»</span></li>";
        if (is_category() || is_single()) {
            echo ' <li>';
            the_category('<span class="separator">»</span></li><li> ');
            if (is_single()) {
                echo "</li><li><span class='separator'>»</span>";
                the_title();
                echo '</li>';
            }
        } elseif (is_page()) {
            echo '<li>';
            echo the_title();
            echo '</li>';
        }
    }
    elseif (is_tag()) {single_tag_title();}
    elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
    elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
    elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
    elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
    elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
    elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
    echo '</ul>';
}

Add the following function in one of your templates. Most times you will use the header.php

<?php xsimu_breadcrumb(); ?>

Congratulations. You are done;)

Pagination for WordPress without Plugin

When i started the creating process of this theme i considered to integrate one of the popular WordPress plugins for pagination. I than  decided to publish the XSimulator theme for free and i felt that it could lead to any problems and issues for someone else to make a similar looking theme when the requirements  are a lot of different plugins he must install first. Fortunately i found a great programmed script which is very easy to implement and powerful.

Open your functions.php and create a new function:

/* Adds pagination 
 * 
 * @since XSimulator 1.0
 * @param $range total list of pages 
 * @param $range count of maximum page links from left and right side of the current page link.
 * @bool $show_one_page_hint shows a text like: page 1 of 6
 * @bool $show_one_pager Do not show nav arrows
 * 
 */
function xsimu_pagination($range = 3, $show_one_pager = true, $show_page_hint = false)
{
    global $wp_query;
    $num_of_pages = (int)$wp_query->max_num_pages;

    if(!is_single() && $num_of_pages > 1)
    {
        $current_page = get_query_var('paged') === 0 ? 1 : get_query_var('paged');
        $num_of_display_pages = ($range * 2) + 1;        

        $output = '<div id="pagination">';

        if($show_page_hint)
        {
            $output .= '<span>Page ' . $current_page . ' of ' . $num_of_pages . '</span>';
        }

		if($current_page > 2 && $current_page > $range + 1 && $num_of_display_pages < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link(1) . '" title="Page 1 - Latest article">«</a>';
		}
		if($show_one_pager && $current_page > 1)
		{
			$output .= '<a href="' . get_pagenum_link($current_page - 1) . '" title="Page ' . ($current_page - 1) . ' - Latest Artikel">‹</a>';
		}

		for($i = 1; $i <= $num_of_pages; $i++)
		{
			if($i < $current_page + $range + 1 && $i > $current_page - $range - 1)
            {
				if($current_page === $i)
				{
					$output .= '<span class="current">' . $i . '</span>';
				}
				else
				{
					$output .= '<a href="' . get_pagenum_link($i) . '" title="Page ' . $i . '" >' . $i . '</a>';
				}
            }
		}

		if($show_one_pager && $current_page < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link($current_page + 1) . '" title="Page ' . ($current_page + 1) . ' - Older article">›</a>';
		}
		if($current_page < $num_of_pages - 1 && $current_page + $range < $num_of_pages && $num_of_display_pages < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link($num_of_pages) . '" title="Page ' . $num_of_pages . ' - Older article">»</a>';
		}

		$output .= '</div>';

        return $output;

    }
}

Open the template file where you want to publish your pagination. E.g. category.php

echo xsimu_pagination(2, true, false);

You´re ready:)

Thanks to the author of the original script on the page smart-webentwicklung.de