Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

N00b problem with gallery menu sorting in php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

N00b problem with gallery menu sorting in php

Postby Tolya » Wed Nov 21, 2012 11:33 am

Hey there, first post on this forum, so hello everyone.

I have a bit of a problem with my wife's website. About two years ago it was coded based on wordpress by a webdeveloper. Right now, Im picking up the admin's mantle, retro-ing the code and trying to figure it out myself so I can do all the necessary modifications. I've ran into a bit of a problem which is way beyond my expertise (html and css coding is mostly my thing, only started learning php).

Here is the problem.

The website in question is http://www.olakalinowska.pl and it is built on wordpress, with the postloop and branding modified to produce the current result. There is a script on the main page which takes all the galleries from a specified album ID and produces a collapsible menu - if you hover on one of the title bars, it will produce a sub-menu with links to specific galleries.

The thing is, the ordering of the galleries seems random. At first I thought it goes by gallery ID, but it does not, if you look at it. I don't think it utilizes any sort of array result ordering.

What I would like it to do is to follow the ordering on the wordpress ngg gallery in the CMS. In the very least, I would like to be able to set the sorting manually. Any help would be greatly appreciated.

<div class="float-me">
<!-- start slub -->
<div id="main-page-slub">
<a class="div-href" href="/slub/">śluby i chrzty</a>
<div class="menu">
<ul>
<li>
<a href="/slub/">śluby i chrzty</a>
<ul id="album-list-slub">
<?php
$aid = 4;
$query = 'SELECT * FROM wp_ngg_album WHERE id = '.$aid.' LIMIT 1'; //album ludzie
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$sort = $row['sortorder'];
}

$gals_ids = implode(',', (unserialize($sort)));

$query = 'SELECT * FROM wp_ngg_gallery WHERE gid IN ('.$gals_ids.')'; //wszystkie galerie z albumu ludzie
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo ('<li><a href="/slub/?album='.$aid.'&gallery='.$row['gid'].'">'.$row['title'].'</a></li>');
}
?>
</ul>
</li>
</ul>
</div>
</div>
<!-- stop slub -->
<div class="shadow-right"></div>
<div style="clear: both;"></div>
<div class="shadow-bottom"></div>

<div style="clear: both;"></div>
</div>
Tolya
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Nov 21, 2012 11:23 am

Re: N00b problem with gallery menu sorting in php

Postby simplypixie » Wed Nov 21, 2012 11:38 pm

Change this line to
Code: Select all
$query = 'SELECT * FROM wp_ngg_gallery WHERE gid IN ('.$gals_ids.') ORDER BY '.$sort.'';
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: N00b problem with gallery menu sorting in php

Postby Tolya » Thu Nov 22, 2012 7:18 am

Thank you, unfortunately it does not work.

When I replace the code, the actual webpage gets parsed only up to the point it stumbles upon that ORDER BY bit. It only renders the first photo without a functional submenu. Inspection of the website source code revealed this:

Something is wrong in your syntax obok ':5:{i:0;s:2:"15";i:1;s:2:"24";i:2;s:2:"14";i:3;s:2:"25";i:4;s:2:"18";}) WHERE gi' w linii 1
Tolya
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Nov 21, 2012 11:23 am

Re: N00b problem with gallery menu sorting in php

Postby simplypixie » Thu Nov 22, 2012 8:46 am

As the ngg gallery is a plugin, have you looked at changing the settings there, not trying to re-write the code?
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: N00b problem with gallery menu sorting in php

Postby Tolya » Thu Nov 22, 2012 11:06 am

Yes, and unfortunately the plugin ordering of galleries does not carry over in any form to the front page script.
Tolya
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Nov 21, 2012 11:23 am

Re: N00b problem with gallery menu sorting in php

Postby Tolya » Thu Nov 22, 2012 2:22 pm

Okay, sorted it out. Created a new field in wp_ngg_gallery named odr, assigned ascending integers to the rows I needed and just ordered by odr.
Tolya
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Nov 21, 2012 11:23 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.