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. 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
On 5/29/2023 at 10:50 AM, chopemp said:

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. 

Thnaks chopemp,I have used this method to sort a menu of categories links and it works (with little changes to the code). Is it possible to override the ps_linklist module to make this change immune from Prestashop updates? I tried to put the modified file, using the same path, inside my graphic theme, but it doesn't work. Do you have any idea what I could do? Thank you

Link to comment
Share on other sites

On 6/8/2017 at 1:35 PM, PrestaDesigner10 said:

Hello, 

how can I reorder the links in the the native module "Widget link" (folder module/ps_linklist)

 

I'm using prestashop 1.7.1.

 

Thanks! 

The module ps_linklist in 1.7.1 doesn’t allow drag-and-drop sorting of links inside a block. Links appear in the order they were created. To change it you either need to recreate the links in the right sequence, adjust them directly in the database, or update to a newer version of the module where link ordering is improved. If the interface still misbehaves, test with the Classic theme and disable other modules to rule out conflicts.

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