Info Harga Komputer dan Gadget

Cara Membuat Halaman Navigasi Bernomor di wordpress tanpa plugin

Advertisement
advertisement

Cara Membuat Halaman Navigasi Bernomor di wordpress tanpa plugin
Kalo kemarin saya posting tentang Cara membuat Pageview di setiap artikel di wordpress tanpa plugin, Kali ini saya akan posting membuat Halaman Navigasi Bernomor di wordpress tanpa plugin, sama halnya dengan sebelumnya kita hanya perlu memasang kode di file functions.php.

Berikut ini langkah-langkah yang harus dilakukan :
Login ke dashboard wordpress
pilih menu Appearance > Editor
Pilih file functions.php
kemudian tambahkan kode ini :

### Function: Page Navigation: Boxed Style Paging
function wp_pagenavi($before = '', $after = '') {
global $wpdb, $wp_query;
if (is_single())
return;
$pagenavi_options = array();
$pagenavi_options['pages_text'] = __('Page %CURRENT_PAGE% of %TOTAL_PAGES%');
$pagenavi_options['current_text'] = '%PAGE_NUMBER%';
$pagenavi_options['page_text'] = '%PAGE_NUMBER%';
$pagenavi_options['first_text'] = __('« First');
$pagenavi_options['last_text'] = __('End');
$pagenavi_options['next_text'] = __('Next');
$pagenavi_options['prev_text'] = __('Back');
$pagenavi_options['dotright_text'] = __('...');
$pagenavi_options['dotleft_text'] = __('...');
$pagenavi_options['style'] = 1;
$pagenavi_options['num_pages'] = 5;
$pagenavi_options['always_show'] = 0;
$request = $wp_query->request;
$posts_per_page = intval(get_query_var('posts_per_page'));
$paged = intval(get_query_var('paged'));
$numposts = $wp_query->found_posts;
$max_page = intval($wp_query->max_num_pages);
if (empty($paged) || $paged == 0)
$paged = 1;
$pages_to_show = intval($pagenavi_options['num_pages']);
$larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
$larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor($pages_to_show_minus_1/2);
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged - $half_page_start;
if ($start_page <= 0)
$start_page = 1;
$end_page = $paged + $half_page_end;
if (($end_page - $start_page) != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if ($end_page > $max_page) {
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
}
if ($start_page <= 0)
$start_page = 1;
$larger_pages_array = array();
if ( $larger_page_multiple )
for ( $i = $larger_page_multiple; $i <= $max_page; $i += $larger_page_multiple )
$larger_pages_array[] = $i;
if ($max_page > 1 || intval($pagenavi_options['always_show'])) {
$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
echo $before.'<div class="wp-pagenavi">'."\n";
switch(intval($pagenavi_options['style'])) {
// Normal
case 1:
if (!empty($pages_text)) {
echo '<span class="pages">'.$pages_text.'</span>';
}
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
echo '<a href="'.clean_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>';
if (!empty($pagenavi_options['dotleft_text'])) {
echo '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
}
}
$larger_page_start = 0;
foreach($larger_pages_array as $larger_page) {
if ($larger_page < $start_page && $larger_page_start < $larger_page_to_show) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($larger_page), $pagenavi_options['page_text']);
echo '<a href="'.clean_url(get_pagenum_link($larger_page)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
$larger_page_start++;
}
}
previous_posts_link($pagenavi_options['prev_text']);
for($i = $start_page; $i <= $end_page; $i++) {
if ($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
echo '<span class="current">'.$current_page_text.'</span>';
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
}
}
next_posts_link($pagenavi_options['next_text'], $max_page);
$larger_page_end = 0;
foreach($larger_pages_array as $larger_page) {
if ($larger_page > $end_page && $larger_page_end < $larger_page_to_show) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($larger_page), $pagenavi_options['page_text']);
echo '<a href="'.clean_url(get_pagenum_link($larger_page)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
$larger_page_end++;
}
}
if ($end_page < $max_page) {
if (!empty($pagenavi_options['dotright_text'])) {
echo '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
}
$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
echo '<a href="'.clean_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>';
}
break;
// Dropdown
case 2;
echo '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']).'" method="get">'."\n";
echo '<select size="1" onchange="document.location.href = this.options[this.selectedIndex].value;">'."\n";
for($i = 1; $i <= $max_page; $i++) {
$page_num = $i;
if ($page_num == 1) {
$page_num = 0;
}
if ($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
echo '<option value="'.clean_url(get_pagenum_link($page_num)).'" selected="selected" class="current">'.$current_page_text."</option>\n";
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<option value="'.clean_url(get_pagenum_link($page_num)).'">'.$page_text."</option>\n";
}
}
echo "</select>\n";
echo "</form>\n";
break;
}
echo '</div>'.$after;
}
}

kemudian klik tombol Update File.
lalu pilih file index.php hapus kode ini :

<div class="navigation">
<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
</div>

kemudian ganti Dengan kode ini :
<div class ="wp-pagenavi"><?php wp_pagenavi(); ?></div>

Klik Update File.
nah sekarang kita atur css agar lebih rapi, caranya pilih file style.css kemudian masukan kode css ini :
.wp-pagenavi{
text-align:center;
margin-bottom:21px;
margin-top:15px; clear:both;
}

.wp-pagenavi a, .wp-pagenavi span{
text-decoration:none;
font-weight:normal; border:1px solid #ddd;
padding:3px 5px; margin:2px;
}

.wp-pagenavi a:hover, .wp-pagenavi span.current{
background-color:#06F;
border-color:#FFF;
color:#FFF;
}

.wp-pagenavi span.current{
font-weight:normal;
background:#333;
}
Klik Update file dan lihat hasilnya. untuk demo bisa di lihat di it.edikomputer.com

Selamat mencoba....
advertisement

10 comments:

NetterKu said...

Nanti di coba klw sudah dekat dengan wordpress dan tahu mengenai platform wordpress...hehehee :D

Wayan Katel said...

Hmm, kalau saya sih udah langsung bawaan themesnya jadi gak perlu repot" buat nambahinny... sekalian ijin bookmark kalau nanti membutuhkan :)

edikomputer said...

kita sambil belajar aja sob he..he..

edikomputer said...

monggo di bookmark atau di save di word buat arsip tutorial

News IP said...

wah terima kasih sob tutornya.. :D tapi apabila navigation number itu dishow secara default tanpa setting robots.txt nanti jadi duplicate content.. :D pada wordpress kan sudah banyak yg seperti itu :D

jadi kita juga bisa setel navigation dengan pagging /3/* atau /4/* atau /5/* dan seterusnya sesuai banyak showing pagging yang inginn ditampilkan dan sesuai dengan halamanyang keluar :D


lama gk kesisni.. :D kunjungan nih.. :D

situsku udah selesai meintenance, sekarang udah bisa BW lagi.. :D

Lintas Line said...

nice share gan, saya cuman bisa nyimak aja soalnya gi gak pakai wordpress tapi tutorialnya bermanfaat sob.

Muhammad Ardiyansah said...

Gan di WP ane Kok g jalan kenapa ya? ane pake Theme Adapt

http://dnhtalenta.com/

Edikomputer said...

Ane Cek Udah bisa tuh gan

jam tangan original said...

mantap gan, terima kasih banyak ya atas ilmunya.. :)

charger laptop said...

Infonya mantap bro, benar nggak sih bro kalau pake page navi ini akan menyebabkan duplikat content? Mohon pencerahannya.

Post a Comment

Blog Ini Dofollow Ya bro tapi jangan nyepam komentar secara bijak dan sesuai dengan postingan