ahmet2106 / pico-navigation

Pico Flat File Based CMS Plugin for better navigation with editable id and class config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Integration of Pico-Placing

klickreflex opened this issue · comments

Hi and thanks for this really useful plugin. The only feature I'm missing is to have a method to manually sort page order. @ollierik has written a plugin called Pico-Placing that allows you to set a page order number in its meta data and thus controlling your menu order. Unfortunately it doesn't work with at_navigation. It would be cool to integrate this functionality in at_navigation so we'd have one module for all navigation needs. I already tried but didn't succeed.

Regards,
Daniel

I was a bit stupid when trying to combine these two modules.I got it working now and I'll attach a patch.

If pages have a Metadata tag called Placing: [int] menu items will be ordered by that.

To enable Placing there's a setting in config.php: $config['pages_order_by'] = 'placing';.

I'm not the author of Pico-Placing, I only merged this highly appreciated functionality into Pico-Navigation. Also, I'm not sure weather pull requests are welcome and if, how it's done, but I'm totally willing to learn how to do so.

From 5d814550f728a86de276a5c70a129fb48864dc6f Mon Sep 17 00:00:00 2001
From: Daniel Wentsch <hello@wentsch.me>
Date: Mon, 27 Jan 2014 09:57:16 +0100
Subject: [PATCH] Integrated Pico-Placing into at-navigation

---
 plugins/at_navigation.php | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/plugins/at_navigation.php b/plugins/at_navigation.php
index c32d79a..761c987 100755
--- a/plugins/at_navigation.php
+++ b/plugins/at_navigation.php
@@ -17,6 +17,17 @@ class AT_Navigation {
    ##
    # HOOKS
    ##
+
+   public function before_read_file_meta(&$headers) 
+   {
+       $headers['placing'] = 'Placing';
+   }
+
+   //get_page_data(&$data, $page_meta)
+   public function get_page_data(&$data, $page_meta) 
+   {
+       $data['placing'] = isset($page_meta['placing']) ? intval($page_meta['placing']) : 0;
+   }

    public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page)
    {
@@ -30,9 +41,24 @@ class AT_Navigation {
                $navigation = array_merge_recursive($navigation, $this->at_recursive($_split, $page, $current_page));
            }
        }
-       
-       array_multisort($navigation);
-       $this->navigation = $navigation;
+
+
+       if ($config['page_order_by'] = 'placing') 
+       {
+           $placing_id = 0;
+           foreach ($pages as $page) {
+               $navigation[$page['placing'] . $placing_id] = $page;
+               $placing_id++;
+           }
+
+           ksort($navigation);
+           $this->navigation = $navigation;
+       } 
+       else 
+       {
+           array_multisort($navigation);
+           $this->navigation = $navigation;
+       }
    }

    public function config_loaded(&$settings)
-- 
1.8.4.2

Sorry, I'm a little confused. Doesn't work yet.

Thanks for your request, I'll look over that the followin days :)

But always - If you got some cool Features workin with pico-navigation, just open a pull request by calling https://github.com/ahmet2106/pico-navigation/compare/ and comparing the newest source with yours. Select the latest - add some content and open a pull request :) 👍
But the most important thing is that your requested code should work

this integration is indeed needed! 👍

@jojoyuji @klickreflex I'll add your fix. thanks for your support

I really need this too =)

I spent more than a day out to solve this problem, but I did not succeed. you can be the creator of pico placing plugin join forces?

I'll try to implement a sorting order to my pico-navigation plugin the next week, pico placing has some difference and is not that easy to implement. Let me know if you'll get it work :-) maybe with a pull request.
Thanks!

I found a solution, and I was able to do the sorting, so that I was needed. And my great pleasure to do pull-request, but I adjusted the code to suit your needs, removing from there check for config string 'placing', so need a little refactoring to plugin to work properly for everyone, not just for me )))

@goq Is it possible to share your solution ? :) Thanks !

Any solution on this issue to share? Still not integrated.

@shango I used at_navigation for quick menu deployment with active class.

Since Pico-Placing wasn't working, I simply use this in my template

        <nav>
            <ul class="nav">
                {% for page in pages %}
                    {% if meta.title == page.title %}
                        <li class="is-active"><a href="{{ page.url }}">{{ page.title }}</a></li>
                    {% else %}
                        <li><a href="{{ page.url }}">{{ page.title }}</a></li>
                    {% endif %}
                {% endfor %}
            </ul>
        </nav>