All posts by RaceRay

Written by

"Enthusiastic Sim-Racer from the north of germany. I write here about web development, hardware, software and latest motion simulator technologies."

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

Joyrider Motion Simulator

This is just an example project description. We are still busy in relaunching the new site, so please be patient and come back soon here. In the meantime why not look into our active community http://www.xsimulator.net/community

At this stage the joyrider is very much a proof of concept. The JRK is fantastic easy, all the components work nicely together, the winch can handle the ±36° up and down easily (18-20 A consumption max. so far)! Several things will need adjustment:

  • The gear ratio of the drive must be lower, i.e. the movements are too slow.
  • The backlash is hilarious. The bicycle chain is not the most efficient way to drive this platform. A timing belt might be better.
  • The computer needs an upgrade. The poor little Pentium®4 @ 3 GHz with rFactor @ 1920×1080, x-sim Sender and Profiler running is by far overloaded
  • The second axis must be constructed. A 1DoF is not worth the effort – although it’s quite impressive how much more you feel like driving with the movement.
  • Tidy up the cables and paint the rosty steel…

More to come…