I have some 'unique' tags, e.g there is only one instance of such a tag.
using printAllTagsAs() clicking such a tag first takes you to the search php from where only, since it is unique, one image or album shows up.
what I wanted is for these 'unique' tags to go straight to the image or album page.
I kind of hustled together something that works for albums with a 'unique' tag.
in the function printAlltagsAs() I added an if condition for the '$val', so if a tag occures only once a different link is printed, one straight to the album or image;
`
if ($val==1){
$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
$path=rewrite_path("/index.php?album=" . urlencode($a[2]));
echo "t
".$key."n";
}else{
$key = str_replace('"', '', $key);
echo "t
getSearchURL($key, '', SEARCH_TAGS, 0, 0)."\"$size rel=\"nofollow\">".
$key.$counter."n";
}
`
this works well for albums with only one unique tag, you can see it at www.bertsimons.nl e.g the tags 18+ or wishlist take you straight to these albums
unfortunatly my sql query knowledge is not enough to write a query that also queries the images and returns their location if the single tag matches the key.
any suggestions?
Comments
`if ($val==1){
$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";
$album = mysql_query($sql);
if ($album) {
$a = mysql_fetch_array($album);
$path=rewrite_path("/index.php?album=" . urlencode($a[2]));
echo "t".$key."n";
} else {
$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";
$image = mysql_query($sql);
}
}else{
$key = str_replace('"', '', $key);
echo "t
getSearchURL($key, '', SEARCH_TAGS, 0, 0)."\"$size rel=\"nofollow\">".
$key.$counter."n";
}`
but is is working.. see the tag unique on my site..
code used to get the image link was this `{
$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";
$image = mysql_query($sql);
$i = mysql_fetch_array($image);
$albumid = $i[1];
$image = $i[2];
$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$albumid."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$album = $album[2];
$path=rewrite_path("/index.php?album=" . $album ."&image=".$image);
echo "t".$key."n";
}`
thanks!
BertSimons: I also suggest that you use the db functions we have, would save you a few lines of code...:-)
That would look like `$i = query_full_array("SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'")` for the first query.
so had to add something. code is now
`if(!$links) {
echo "t".$key.$counter."n";
} else {
if ($val==1){
$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
if (!empty($a)) { $path=rewrite_path("/index.php?album=" . urlencode($a[2]));
echo "t".$key."n";
}else{
$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";
$image = mysql_query($sql);
$i = mysql_fetch_array($image);
$albumidimage = $i[1];
$image = $i[2];
$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$albumidimage."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$albumpath = $album[2];
$passwordcheck=$album[18];
if (empty($passwordcheck)){
$path=rewrite_path("/index.php?album=" . $albumpath ."&image=".$image);
echo "t".$key."n";
}
}
}else{
$key = str_replace('"', '', $key);
echo "t
getSearchURL($key, '', SEARCH_TAGS, 0, 0).""$size rel="nofollow">".
$key.$counter."n";
}
}
}
} // while end
echo "n";
}`
so it works with me here, second opinion testing required off course.
I guess getting the fields from the query table with $album[18] etc is not so nice when table fields are going to be added and the nuber changes
You could take a look at the rss feed of the nightly where this is used.
i'll look into that later this week
Somehow what is needed is to use the zenphoto search again for the unique tag.
perhaps it's to do like this
$val now is calculated by getAlltags which is defined in the templates function only to select those WHERE show = 1
so a new function getAllTagsEvenThoseWhoAreHidden() could return the number of a certain tag including hidden and protected images.
then in the PrintTagsAs() function the number could be reduced by 1 if an image or album with this tage is set as not shown and also be reduced by one if the image has a password.
If this results in a number of 1 the tag can be considered as a unique tag to up show in the taglist, and then depending on if it's in a parent album which is protected or set to invisble be shown or not.
`if ($val=1) {
$search = new SearchEngine();
$search->words = $uniqueTag;
$search->fields = SEARCH_TAG;
$search->dates = '';
$uniqueAlbum = $search->getAlbums();
if (count($uniqueAlbum) > 0) {
} else {
$uniqueImage = $search->getSearchImages();
if (count($uniqueImage) > 0) {
} else {
}`
This way the search engine will be using the same queries/password protection as the tag query.
Of course the stuff within the `<` `>` is left to the 'student' as the professor likes to say.
before printing the unique tag link i checked in a while loop if one of the unique tagged image's or album's parent albums is flagged as protected or invisible and if so not to print it's link.
`
...................
echo "t".$key.$counter."n";
} else {
if ($val==1){
$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$parentid = $album[1];
$path=rewrite_path("/index.php?album=" . urlencode($album[2]));
if (!empty($album)) {
$check=0;
while (!empty($parentid)) {
$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$parentid."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$parentid = $album[1];
if ($album[7] == 0){$check=$check+1;}
if (!empty($album[18])){$check=$check+1;}
}
if ($check <1 ){<br />
echo "t".$key."n";
}
}else{
$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";
$image = mysql_query($sql);
$image = mysql_fetch_array($image);
$albumidimage = $image[1];
$imagepath = $image[2];
$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$albumidimage."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$parentid = $album[1];
$albumpath = $album[2];
$path=rewrite_path("/index.php?album=" . $albumpath ."&image=".$imagepath);
$check=0;
if ($album[7] == 0){$check=$check+1;}
while (!empty($parentid)) {
$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$parentid."%'";
$album = mysql_query($sql);
$album = mysql_fetch_array($album);
$parentid = $album[1];
if ($album[7] == 0){$check=$check+1;}
if (!empty($album[18])){$check=$check+1;}
}
if ($check <1 ){<br />
echo "t".$key."n";
}
}
}else{
$key = str_replace('"', '', $key);
echo "t
getSearchURL($key, '', SEARCH_TAGS, 0, 0).""$size rel="nofollow">".
$key.$counter."n";
}
}
}
} // while end
echo "n";
}
`
for unique tags this works but if there is more then one occurence of a tag, the standart last part of the PrintAllTagsAS() code goes still leads to the search.php where images or albums in invisible albums still are printed...