Jump to content

Widget Link (ps_linklist) - How can I order links?


Recommended Posts

  • 2 weeks later...
  • 9 months later...

No the best way I do direct on database

check ps_link_block

you see something like these

{"cms":["1","2","3","4","5"],"product":[false],"static":["contact","sitemap","stores"]}

the numeber are the id of the content just change the number

{"cms":["2","1","3","4","5"],"product":[false],"static":["contact","sitemap","stores"]}

 

 

 

 

 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 years later...
  • 3 months later...
  • 5 months later...

Hello.

First of all thank you very much for the attention and disinterested help.

According to what you have indicated, how should I indicate to display first the categories and then the "product" part:{"1": "new-products", "2": "best-sales"}

{"cms":[false],"static":[false],"product":{"1":"new-products","2":"best-sales"},"category":["10","3","9","11","12","6","13","1","15","14"]}

Thank you very much

Link to comment
Share on other sites

  • 1 year later...

You need to modify the ps_linklist module as below: 

in modules/ps_linklist/src/Presenter/LinkBlockPresenter.php around line 126, change the makeCmsLinks function as below: 

    /**
     * @param array $cmsIds
     *
     * @return array
     *
     * @throws \PrestaShopDatabaseException
     * @throws \PrestaShopException
     */
    private function makeCmsLinks($cmsIds)
    {
        $cmsLinks = [];
        foreach ($cmsIds as $cmsId) {
            $cms = new \CMS((int) $cmsId);
            if (null !== $cms->id && $cms->active) {
                $cmsLinks[] = [
                    'id' => 'link-cms-page-' . $cms->id,
                    'class' => 'cms-page-link',
                    'title' => $cms->meta_title[(int) $this->language->id],
                    'description' => $cms->meta_description[(int) $this->language->id],
                    'url' => $this->link->getCMSLink($cms),
                    'position' => $cms->position,
                ];
            }
        }
        
        // Extract the 'position' attribute values into a separate array
        $positions = array_column($cmsLinks, 'position');
        // Sort the array of cmsLinks based on the 'position' attribute
        array_multisort($positions, $cmsLinks);

        return $cmsLinks;
    }

This will sort the links according to their "position" attribute. 

Link to comment
Share on other sites

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...