Aanpassen archief pagina
Ik heb een klein probleempje met mijn archiefpagina en wel het volgende:
Het maandarchief toont alleen de laatste 10 berichten en niet alle berichten die in die maand geplaatst zijn. Er is ook geen paginanummering op de pagina te zien.
Nu ben ik er inmiddels achter dat het probleem in mijn template zit dus nu is mijn vraag of iemand mij kan helpen met het aanpassen van mijn files zodat ik een goed werkend archief heb.
Je kan mijn archief pagina bekijken via deze link
Ik wil graag dat het mogelijk is om door de maanden te bladeren dus dat er naast "Maand Archief: mei 2012" een link komt naar de volgende en de vorige maand.
Ook zou ik graag een paginanummering onder de pagina willen hebben zodat het mogelijk is om naar de volgende berichten in het archief te gaan.
Ik heb 2 files gevonden die van invloed zijn op mijn archief en dat zijn:
archive.php
loop2.php (was eerst loop.php maar dit is een kopie en die heb ik bewerkt om meer berichten te zien want eerst zag ik maar 6 berichten)
Hier de code van archive.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/*
Template Name: Archive
*/
?>
<?php get_header(); ?>
<div id="content" class="content-group content-archive">
<div class="wrapper">
<div class="post-group">
<?php the_post(); ?>
<?php if (is_day()) : ?>
<h1 class="title">Dag Archief: <?php the_date(); ?></h1>
<?php elseif (is_month()) : ?>
<h1 class="title">Maand Archief: <?php the_date('F Y'); ?></h1>
<?php elseif (is_year()) : ?>
<h1 class="title">Jaar Archief: <?php the_date('Y'); ?></h1>
<?php else : ?>
<h1 class="title">Blog Archief</h1>
<?php endif; ?>
<?php rewind_posts(); ?>
<?php get_template_part('loop2','archive'); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
/*
Template Name: Archive
*/
?>
<?php get_header(); ?>
<div id="content" class="content-group content-archive">
<div class="wrapper">
<div class="post-group">
<?php the_post(); ?>
<?php if (is_day()) : ?>
<h1 class="title">Dag Archief: <?php the_date(); ?></h1>
<?php elseif (is_month()) : ?>
<h1 class="title">Maand Archief: <?php the_date('F Y'); ?></h1>
<?php elseif (is_year()) : ?>
<h1 class="title">Jaar Archief: <?php the_date('Y'); ?></h1>
<?php else : ?>
<h1 class="title">Blog Archief</h1>
<?php endif; ?>
<?php rewind_posts(); ?>
<?php get_template_part('loop2','archive'); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Hier de code van loop2.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php if (!have_posts()) : ?>
<div id="post-0" class="post error404 not-found">
<h1 class="title">Not Found</h1>
<div class="entry-content">
<p>Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.</p>
</div>
</div>
<?php else : ?>
<?php
add_filter('excerpt_length', 'padd_theme_excerpt_index_length');
$countposts = 0;
?>
<?php while (have_posts()) : ?>
<?php the_post();
if($countposts <= 14){
?>
<div id="post-<?php the_ID(); ?>" class="post entry">
<div class="t"></div>
<div class="m">
<div class="thumbnail">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php padd_theme_post_thumbnail(); ?>
</a>
</div>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p class="meta"><span class="date-cat"><?php the_time('F j, Y'); ?></span></p>
<div class="excerpt">
<?php the_excerpt();?>
</div>
</div>
<div class="b clear"></div>
</div>
<?php
}
$countposts++;
endwhile; ?>
<?php remove_filter('excerpt_length', 'padd_theme_excerpt_index_length'); ?>
<div class="clear"></div>
<?php endif; ?>
<div id="post-0" class="post error404 not-found">
<h1 class="title">Not Found</h1>
<div class="entry-content">
<p>Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.</p>
</div>
</div>
<?php else : ?>
<?php
add_filter('excerpt_length', 'padd_theme_excerpt_index_length');
$countposts = 0;
?>
<?php while (have_posts()) : ?>
<?php the_post();
if($countposts <= 14){
?>
<div id="post-<?php the_ID(); ?>" class="post entry">
<div class="t"></div>
<div class="m">
<div class="thumbnail">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php padd_theme_post_thumbnail(); ?>
</a>
</div>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p class="meta"><span class="date-cat"><?php the_time('F j, Y'); ?></span></p>
<div class="excerpt">
<?php the_excerpt();?>
</div>
</div>
<div class="b clear"></div>
</div>
<?php
}
$countposts++;
endwhile; ?>
<?php remove_filter('excerpt_length', 'padd_theme_excerpt_index_length'); ?>
<div class="clear"></div>
<?php endif; ?>
Met vriendelijke groet,
John
in loop2.php: je opent en sluit op regel 10, je opent dan weer op 12 en sluit op 15 om op 16 te openen. Etc.
Niemand die mij kan helpen? Ik heb al een script van deze site geprobeerd voor de paginanummering maar ik krijg het niet werkend....
Gewijzigd op 22/05/2012 21:48:45 door John van den Oudenhoven
als dat zo is kan je het getal van 5 naar 100 aanpassen maar zullen er nooit meer dan 10 komen.
Ik heb geen idee, hoe kan ik dat zien?
Ik ben een echte beginner met php.
een aantal recods ophaalt.
Je zou deze functie moeten opzoeken en kijken of er een limit 10 in de SQL staat.
Stap voor stap door de code heenlopen en de logica erachter proberen te achterhalen om het juiste resultaat te krijgen lijkt mij de volgende logische stap.
ik kan natuurlijk niet in je volledige bron rondkijken, maar een wilde gok zegt me dat de aanroep Je zou deze functie moeten opzoeken en kijken of er een limit 10 in de SQL staat.
Stap voor stap door de code heenlopen en de logica erachter proberen te achterhalen om het juiste resultaat te krijgen lijkt mij de volgende logische stap.
Welke pagina's/bestanden worden er geinclude in dit script? Wellicht dat je daar moet gaan zoeken, en dan voornamelijk rond de have_posts() functie. Zie waar de SQL query gedraaid wordt, dan moet daar na LIMIT en een variabel staan (of gewoon 10), die bepaald de limit.
Gewijzigd op 23/05/2012 07:21:08 door Chris PHP
Ik heb alleen geen enkel idee wat een query is.... :S
Na aanleiding van de reactie van Chris ben ik in mijn template folder gaan snuffelen en dan kom ik in de submap "classes" het bestand pagination.php tegen. Hieronder de code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
class Padd_PageNavigation {
const ANTE_PAGE = '<span class="t"><span class="l"></span><span class="r"></span></span><span class="m"><span class="l"></span><span class="c">';
const POST_PAGE = '</span><span class="r"></span></span><span class="b"><span class="l"></span><span class="r"></span></span>';
public static function get_nearest_round($num, $to_nearest) {
return floor($num/$to_nearest)*$to_nearest;
}
public static function render() {
global $wpdb, $wp_query;
if (!is_single()) {
$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 = $wp_query->max_num_pages;
if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = intval(get_option(PADD_THEME_SLUG . '_pgn_pages_to_show'));
$larger_page_to_show = intval(get_option(PADD_THEME_SLUG . '_pgn_larger_page_numbers'));
$larger_page_multiple = intval(get_option(PADD_THEME_SLUG . '_pgn_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_per_page = $larger_page_to_show*$larger_page_multiple;
$larger_start_page_start = (Padd_PageNavigation::get_nearest_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
$larger_start_page_end = Padd_PageNavigation::get_nearest_round($start_page, 10) + $larger_page_multiple;
$larger_end_page_start = Padd_PageNavigation::get_nearest_round($end_page, 10) + $larger_page_multiple;
$larger_end_page_end = Padd_PageNavigation::get_nearest_round($end_page, 10) + ($larger_per_page);
if($larger_start_page_end - $larger_page_multiple == $start_page) {
$larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
$larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
}
if($larger_start_page_start <= 0) {
$larger_start_page_start = $larger_page_multiple;
}
if($larger_start_page_end > $max_page) {
$larger_start_page_end = $max_page;
}
if($larger_end_page_end > $max_page) {
$larger_end_page_end = $max_page;
}
if($max_page > 1) {
$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), 'Page %CURRENT_PAGE% of %TOTAL_PAGES%');
$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
echo $before.'<div class="pagination">'."\n";
if(!empty($pages_text)) {
echo '<span class="pages">' . Padd_PageNavigation::ANTE_PAGE . $pages_text . Padd_PageNavigation::POST_PAGE . '</span>';
}
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), '« First');
echo '<a href="'.clean_url(get_pagenum_link()).'" class="first page-word" title="'.$first_page_text.'">' . Padd_PageNavigation::ANTE_PAGE . $first_page_text . Padd_PageNavigation::POST_PAGE . '</a>';
echo '<span class="extend">' . Padd_PageNavigation::ANTE_PAGE . '...' . Padd_PageNavigation::POST_PAGE . '</span>';
}
if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">' . Padd_PageNavigation::ANTE_PAGE . $page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
}
if (($paged - 1) > 0) {
echo '<a href="'.clean_url(get_pagenum_link($paged - 1)).'" class="page prev" title="Previous">' . Padd_PageNavigation::ANTE_PAGE . '« Prev' . Padd_PageNavigation::POST_PAGE . '</a>';
}
for($i = $start_page; $i <= $end_page; $i++) {
if($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<span class="current">'. Padd_PageNavigation::ANTE_PAGE . $current_page_text. Padd_PageNavigation::POST_PAGE . '</span>';
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">' . Padd_PageNavigation::ANTE_PAGE .$page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
}
if (($paged + 1) <= $max_page) {
echo '<a href="'.clean_url(get_pagenum_link($paged + 1)).'" class="page next" title="Next">' . Padd_PageNavigation::ANTE_PAGE . 'Next »' . Padd_PageNavigation::POST_PAGE . '</a>';
}
if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.Padd_PageNavigation::ANTE_PAGE .$page_text . Padd_PageNavigation::POST_PAGE.'</a>';
}
}
if ($end_page < $max_page) {
echo '<span class="extend">...</span>';
$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page),'Last »');
echo '<a href="'.clean_url(get_pagenum_link($max_page)).'" class="last page-word" title="'.$last_page_text.'">' . Padd_PageNavigation::ANTE_PAGE .$last_page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
echo '</div>'.$after."\n";
}
}
}
}
?>
class Padd_PageNavigation {
const ANTE_PAGE = '<span class="t"><span class="l"></span><span class="r"></span></span><span class="m"><span class="l"></span><span class="c">';
const POST_PAGE = '</span><span class="r"></span></span><span class="b"><span class="l"></span><span class="r"></span></span>';
public static function get_nearest_round($num, $to_nearest) {
return floor($num/$to_nearest)*$to_nearest;
}
public static function render() {
global $wpdb, $wp_query;
if (!is_single()) {
$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 = $wp_query->max_num_pages;
if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = intval(get_option(PADD_THEME_SLUG . '_pgn_pages_to_show'));
$larger_page_to_show = intval(get_option(PADD_THEME_SLUG . '_pgn_larger_page_numbers'));
$larger_page_multiple = intval(get_option(PADD_THEME_SLUG . '_pgn_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_per_page = $larger_page_to_show*$larger_page_multiple;
$larger_start_page_start = (Padd_PageNavigation::get_nearest_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
$larger_start_page_end = Padd_PageNavigation::get_nearest_round($start_page, 10) + $larger_page_multiple;
$larger_end_page_start = Padd_PageNavigation::get_nearest_round($end_page, 10) + $larger_page_multiple;
$larger_end_page_end = Padd_PageNavigation::get_nearest_round($end_page, 10) + ($larger_per_page);
if($larger_start_page_end - $larger_page_multiple == $start_page) {
$larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
$larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
}
if($larger_start_page_start <= 0) {
$larger_start_page_start = $larger_page_multiple;
}
if($larger_start_page_end > $max_page) {
$larger_start_page_end = $max_page;
}
if($larger_end_page_end > $max_page) {
$larger_end_page_end = $max_page;
}
if($max_page > 1) {
$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), 'Page %CURRENT_PAGE% of %TOTAL_PAGES%');
$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
echo $before.'<div class="pagination">'."\n";
if(!empty($pages_text)) {
echo '<span class="pages">' . Padd_PageNavigation::ANTE_PAGE . $pages_text . Padd_PageNavigation::POST_PAGE . '</span>';
}
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), '« First');
echo '<a href="'.clean_url(get_pagenum_link()).'" class="first page-word" title="'.$first_page_text.'">' . Padd_PageNavigation::ANTE_PAGE . $first_page_text . Padd_PageNavigation::POST_PAGE . '</a>';
echo '<span class="extend">' . Padd_PageNavigation::ANTE_PAGE . '...' . Padd_PageNavigation::POST_PAGE . '</span>';
}
if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">' . Padd_PageNavigation::ANTE_PAGE . $page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
}
if (($paged - 1) > 0) {
echo '<a href="'.clean_url(get_pagenum_link($paged - 1)).'" class="page prev" title="Previous">' . Padd_PageNavigation::ANTE_PAGE . '« Prev' . Padd_PageNavigation::POST_PAGE . '</a>';
}
for($i = $start_page; $i <= $end_page; $i++) {
if($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<span class="current">'. Padd_PageNavigation::ANTE_PAGE . $current_page_text. Padd_PageNavigation::POST_PAGE . '</span>';
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">' . Padd_PageNavigation::ANTE_PAGE .$page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
}
if (($paged + 1) <= $max_page) {
echo '<a href="'.clean_url(get_pagenum_link($paged + 1)).'" class="page next" title="Next">' . Padd_PageNavigation::ANTE_PAGE . 'Next »' . Padd_PageNavigation::POST_PAGE . '</a>';
}
if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), '%PAGE_NUMBER%');
echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.Padd_PageNavigation::ANTE_PAGE .$page_text . Padd_PageNavigation::POST_PAGE.'</a>';
}
}
if ($end_page < $max_page) {
echo '<span class="extend">...</span>';
$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page),'Last »');
echo '<a href="'.clean_url(get_pagenum_link($max_page)).'" class="last page-word" title="'.$last_page_text.'">' . Padd_PageNavigation::ANTE_PAGE .$last_page_text . Padd_PageNavigation::POST_PAGE . '</a>';
}
echo '</div>'.$after."\n";
}
}
}
}
?>
Moet ik hier iets veranderen? of is dit het verkeerde bestand?
Groet,
John
Dit is geinclude in je script in je eerste post. Daar zal de query gedraaid worden die de database selectie doet, en dus de limitatie doorvoert.
Kan je anders het hele script posten van je eerste bericht?
Bedoel je de post de het langst de site staat of echt de eerste ooit geplaatst? De eerste ooit geplaatst is namelijk verwijderd want dat was het volgende bericht:"dit is een test"
The_post() is een functie die voert iets uitvoerd. Waarschijnlijk hier een select query om je gegevens uit de database te halen.
Berichten die je ooit eens hebt gemaakt staan in je database zelf en staan los van deze funtie.
Tip: Als je notepad++ gebruikt, kan je cntrl+shift+f gebruiken, en dan door mappen heen zoeken.
@John, ik heb hier geen winrar (bedrijfsomgeving). Dus ik kan hem helaas niet openen.
Is er nog iemand die mij verder kan helpen? Ik ben echt een beginnende php gebruiker dus graag een duidelijke uitleg van wat ik moet doen om dit op te lossen.