Jump to content

Recommended Posts

Posted

Hello, 

i need to sort $pages by the first letter an show on the page like 

A

   - Aname Page 

   - Aname Page 

   - Aname Page 

   - Aname Page 

B

   - Bname Page 

   - Bname Page 

   - Bname Page 

   - Bname Page

How can i check which is the first letter from the page.title ?? 

Tnx 

Posted

Hi iNoize,

Checkout this example used by Ryan to view tags in his blog profile:

<?php 

/**
 * Generate a list of tags A-Z
 * 
 * Used by the /site/templats/tags.php template file.
 *
 * VARIABLES: 
 * ==========
 * $tags PageArray of tags
 * 
 * Each of the tags has a numPosts property containing the number of posts used by the tag.
 *
 */

$lastLetter = '';
$out = '';
$letters = array();

foreach($tags as $tag) {
	$letter = strtoupper(substr($tag->title, 0, 1)); 
	if($letter != $lastLetter) {
		if($lastLetter) $out .= "</ul>";
		$out .= "<h3 id='letter_$letter'>$letter</h3>"; 
		$out .= "<ul class='tags posts-group'>";
		$letters[] = $letter; 
	}
	$lastLetter = $letter; 
	$numPosts = sprintf(_n('%d post', '%d posts', $tag->numPosts), $tag->numPosts);
	$out .= "<li><a href='{$tag->url}'>{$tag->title}</a> <span class='num-posts'>$numPosts</span></li>";
}
$out .= "</ul>";

echo "<p class='jumplinks'>";
foreach($letters as $letter) {
	echo "<a href='./#letter_$letter'>$letter</a> ";
}
echo "</p>";
echo $out; 

  • Like 7
Posted

Thank you ver much. It works fine for me. Now i need to loop the array trough three divs. 

Could you give me also some advice ? My idea was to get the count of all $pages and divide it. Then loop for every col from to. 

$lastLetter = '';
$out = '';
$letters = array();

$anzahl = $pages->count("template=kunde,   bereich=$bereich"); // here I have the count but how to llop now trough three divs? 
$kunden = $pages->find("template=kunde,  bereich=$bereich, sort=title");
						

foreach($kunden as $tag) {
$letter = strtoupper(substr($tag->title, 0, 1)); 
if($letter != $lastLetter) {
if($lastLetter) $out .= "</ul>";
$out .= "<h3 id='letter_$letter'>$letter</h3>"; 
$out .= "<ul class='tags posts-group'>";
$letters[] = $letter; 
}
$lastLetter = $letter; 
$out .= "<li><a href='{$tag->url}'>{$tag->title}</a> </li>";
								}
$out .= "</ul>";
echo "<p class='jumplinks'>";
foreach($letters as $letter) {
echo "<a href='./#letter_$letter'>$letter</a> ";
}
echo "</p>";
echo $out; 
							
Posted

Hi, no problem. Could you give an example of a quick mock-up how this should look? I'm not exactly sure what you mean.

Posted

Hi, something like this in the attachment. 

i have 3 divs with bootstrap eg 


<div col-md-4> column 1 </div><div col-md-4> column 2 </div><div col-md-4> column 3 </div>

post-957-0-07769500-1453373527_thumb.png

Posted

I would simply sort pages by title, and echo the first letter only if it's different from the previous.

Posted

thanks for you advice. ive tried this example but its sort for me 

like this 

A A A 

B B B 

but i need 

a  d  h

b  f   i

c  g  j

I think its much more simpler. in the theory i get the count divide it trough 3 dan loop from to every time ?  ist it so ?

Posted
//set counter
$count = 0;

//divider
//$anzahl from your $page->count()
$div_one = $anzahl / 3;  // for example 7
$div_two = $div_one * 2; // for example 14
$div_three = $anzahl;    // for example 21
//loop and check $counter

foreach ($kunden as $tag) {
  $counter++;
  switch ($counter) {
    case ($counter >= $div_one):
        echo "html output with $tags for div one";
        break;
    case ($counter >= $div_two):
        echo "html output with $tags for div two";
        break;
    case ($counter >= $div_three):
        echo "html output with $tags for div three";
        break;
  }
}

this is untested written in the browser....but it should give you a option.

regards mr-fan

Posted

Two uses for this solution -- part of a book back matter (indexing) and newspaper/magazine column layouts.

In a responsive design, you can have a single-column for mobile, two-column for tablet, and three-column for desktop -- similar to iNoize's attached image.

  • Like 1
  • 2 weeks later...
Posted

Oh it was much more easier  :blush:

$letter = strtoupper(mb_substr($tag->title, 0, 1, 'UTF-8'));

works now 

Hello, 

I have a strange output problem now. ÄÜÖ dont show correctly 

It looks so 

post-957-0-57416700-1454395777_thumb.png

What happens here and how to convert to the right chars ? 

$letter = strtoupper(substr($tag->title, 0, 1)); 

Tnx 

  • 3 years later...
Posted

I want to display all A-Z letters, if letter does not have any page then it is  unavailable or block  else letter should be active..

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...