Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To do what you want to do using Views, and not some other contributed module, like Glossary, you'll have to define and theme your own view. </p> <p>First, you'll need to create a new node View. I'm going to call it myglossary, but it doesn't matter. Make sure that one of your fields is the node title, and that it's sorted by node title, ascending. In other words, alphabetical order. I'm assuming you'll be using the unformatted row style (it's default), but you can probably do something similar with the other row styles.</p> <p>Then, you'll have to get into your theme. From the views/theme folder, copy the views-view-unformatted.tpl.php template into the folder of the theme you're using. Rename it to views-view-unformatted--myglossary.tpl.php so it will only be used for this view. Then, open up your theme's template.php file, and add a preprocess function:</p> <pre><code>//Change mytheme to your theme name function mytheme_preprocess_views_view_unformatted__myglossary(&amp;$vars) { //If you have the devel module installed, //this is a great way to see all the available variables //dpm($vars); $results = $vars['view']-&gt;result; $rows = $vars['rows']; //Sort rows into letter sets $letters = array(); $i = 0; foreach ($results as $result) { $first_letter = strtolower(substr($result-&gt;node_title, 0, 1)); if (is_array($letters[$first_letter])) { array_push($letters[$first_letter], $rows[$i]); } else { $letters[$first_letter] = array($rows[$i]); } $i++; } //Generate glossary navigation $nav = ''; foreach($letters as $letter =&gt; $rows) { $num = count($rows); $cap_letter = strtoupper($letter); $nav .= &lt;&lt;&lt;NAV &lt;a href="#$letter" class="letter_link"&gt; $cap_letter &lt;/a&gt; ($num) NAV; } //Add to variables $vars['nav'] = $nav; $vars['letters'] = $letters; } </code></pre> <p>Then, you'll have to change the template file you copied over earlier to add in the navigation, and to output the rows in a glossary style:</p> <pre><code>&lt;?php if (!empty($title)): ?&gt; &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt; &lt;?php endif; ?&gt; &lt;?php if (!empty($nav)): ?&gt; &lt;div id="glossary_nav"&gt; &lt;?php print $nav; ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;?php foreach ($letters as $letter=&gt;$rows): ?&gt; &lt;a name="&lt;?php print $letter ?&gt;"&gt;&lt;/a&gt; &lt;h4 class="letter"&gt; &lt;?php print strtoupper($letter); ?&gt; &lt;/h4&gt; &lt;?php foreach ($rows as $id=&gt;$row): ?&gt; &lt;div class="&lt;?php print $classes[$id]; ?&gt;"&gt; &lt;?php print $row; ?&gt; &lt;/div&gt; &lt;?php endforeach;?&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>You might need to regenerate the theme registry to have your changes show up on your site.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload