Image by page alias?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Eni
Regular
Posts: 62
Joined: Thu Jan 27, 2005 10:47 pm
Location: Münster, Germany

Image by page alias?

Post by Eni »

Hm, does someone want to help me with a tweak?

I have an image in the sidebar, using the HTML Nugget:

Code: Select all

<div id="nugget"></div>
In style.css:
#nugget {
width:305px;
height:250px;
margin:0 auto;
background: url("{TEMPLATE_PATH}img/nuggetpic.png") top right no-repeat;
}
"nuggetpic.png" is a folder, not a file. The folder contains a index.php:

Code: Select all

<?php Header("Content-Type: image/gif");
$sigarray=array();
if ($handle = opendir("./")) {
  while (false !== ($file = readdir($handle))) { 
  if(stristr($file, ".gif") or stristr($file, ".jpg") or stristr($file, ".png")){
  array_push($sigarray,$file);} } }
closedir($handle);
shuffle($sigarray);
readfile(end($sigarray));?>
.... and a couple of images which are randomly rotated through this script.

Problem: The images load very slow and the "random" doesn't work well. It takes a couple of refreshes to get another image. That's why, instead of random, I'd like to call the images by page alias (category AND static pages). So when static page "profile" is called, the image "profile.png" would be load. When category "education" is called, the image "education.png" is called. When no alias matches, a fallback image is called.

At least, that's how I call a individual banner per page on my homepage. But I can't figure out what "alias" to use in case of serendipity when applying it to static pages AND categories. Is that even possible? Or am I on a completely wrong track on how to adapt my homepage script? Or is there maybe a plugin solution I can abuse for this?

This is how I have it on my little homepage (no blog system):

index.php

Code: Select all

<div id="header"><img src="<?php include("inc/banner.php") ;?>" alt="banner" /></div>
banner.php

Code: Select all

<?php 
	if(isset($_GET['section']) AND isset($banner[$_GET['section']])) {
		echo $banner[$_GET['section']]; 
	} else {
		echo $banner['home'];
	} 
?>
config.php

Code: Select all

 // banner 
    $banner = array();
    $banner['home'] = "inc/banner/home.png";
    $banner['links'] = "inc/banner/links.png";
[...]
But I suppose it won't work that easy with serendipity. My skills in PHP kinda end with this, though. Can I adapt it the same way to serendipity for category and static pages? But what do I need to call? I'm sorry if I overlook something obvious, this is really not easy for me to comprehend.

Questions, questions,... I promise this is the last for now ^^;

~eni
Sorry, I'm Late. But I Got Lost On The Road Of Life.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Image by page alias?

Post by garvinhicking »

Hi!

Well. There are a couple of opportunities you could use. The two most promising would be:

1. There's a plugin serendipity_event_categorytemplates. This one allows you to use a specific template per category, which would allow you to create distinct templates (and banners) for each category you might want to style. This would be easiest to setup, but has the most redundancy.

2. The "hard" way is to go your route. You would neet to pass {$category_info.category_name} for example:

Code: Select all

{if $staticpage_pagetitle}
<img src="/banners/staticpage.php?var={$staticpage_pagetitle}" />
{elseif $category_info.category_name}
<img src="/banners/staticpage.php?var={$category_info.category_name}" />
{else}
<img src="/banners/staticpage.php?var=other" />
{/if}
I'm not a hundert percent sure if it's $category_info.category_name or maybe $category_info.0.category_name; you might want to use {$category_info|print_r} on index.tpl or wherever to see what's inside the array.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Eni
Regular
Posts: 62
Joined: Thu Jan 27, 2005 10:47 pm
Location: Münster, Germany

Re: Image by page alias?

Post by Eni »

Hi Garvin,

sorry for the late reply, it was a bit stressful at home :)

What I don't like about the plugin is that I need to keep several clones of my template just to switch one small image. It also sadly has no affect on static pages, even if they're related to one category in the settings. Hmm.

The other way seems to not work well either. I want to change an image in the HTML Nugget but can't call a PHP include inside of it, as I noticed now. So I'm trying to use the fake image php:

Code: Select all

<?php Header("Content-Type: image/png");
readfile('other.png');
?>
That works fine. But adding any code before 'readfile' to call the if/else for static pages and category seems to either not work with this method or I do it wrong. Can't I do this in this php content type? :?

~eni
Sorry, I'm Late. But I Got Lost On The Road Of Life.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Image by page alias?

Post by garvinhicking »

Hi!

You mean you can't pass a URL parameter to your image.php? That should work properly...did you try to simply dump your $_REQUEST vars to see what parameter you get?

Maybe you can send a larger image.php sample to let us see what you tried.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Eni
Regular
Posts: 62
Joined: Thu Jan 27, 2005 10:47 pm
Location: Münster, Germany

Re: Image by page alias?

Post by Eni »

Good Morning,

my bad, Garvin. I tried with the normal include command instead of the one for smarty. That wouldn't work but now it's fine.

Still not 100% working as I want it to be but I'm sure I can figure that out. Else I'll poke again :mrgreen:

Thank you~

~eni
Sorry, I'm Late. But I Got Lost On The Road Of Life.
Eni
Regular
Posts: 62
Joined: Thu Jan 27, 2005 10:47 pm
Location: Münster, Germany

Re: Image by page alias?

Post by Eni »

Hmm, I need two hints.

This is how I call the banner per static page and category now and it works great:

Code: Select all

{if $staticpage_pagetitle}
<img src="templates/mimbo/inc/banner/{$staticpage_pagetitle}.png" />
{elseif $category_info.category_name}
<img src="templates/mimbo/inc/banner/{$category_info.category_name}.png" />
{else}
<img src="templates/mimbo/inc/banner/fallback.png" />
{/if}
Now, when I view an entry, I would like to call the *.png of it's category. Right now it would get the fallback banner. I'm looking allover the parameters but I can't really figure out how to add a line to this snippet that says "if entry-of-category-x include category-x.png". Any idea what parameter to use for this?


Related problem: I'm trying to call a custom submenu with the same code snippet:

Code: Select all

{if $staticpage_pagetitle}
{include file="inc/menu/$staticpage_pagetitle.inc"}
{elseif $category_info.category_name}
{include file="inc/menu/$category_info.category_name.inc"}
{else}
{include file="inc/menu/fallback.inc"}
{/if}
The first part (static page) and the last part (fallback) work fine, but the category part displays nothing, not even the fallback. I assume it has trouble with the 'dot' when calling the parameter?

I tried changing it to:

Code: Select all

{elseif $category_info[category_name]}
{include file="inc/menu/$category_info[category_name].inc"}
Then it displays at least the fallback menu when I go to a category but that's it. Can I write this line somehow differently to make it work? :?

I know this solution with lots of little inc-files for submenus is a bit work intensive. But I looked allover the forum yesterday and don't really like any of the automatic solutions to only display child categories.

~eni
Sorry, I'm Late. But I Got Lost On The Road Of Life.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Image by page alias?

Post by garvinhicking »

Hi!

This is because when you view a single blog entry, you are not actually viewing its category, thus no $category_info exists.

You have two ways to solve this. First one is easiest - install the category_templates event plugin, this also has an option to assign the global category when a entry detail is viewed. So then your $category_info would be existing properly.

The other way would be in the place where you currently output your banner, you would need to place a foreach-loop around {$entries} just to capture and store the variable that belongs to the currently displayed entry. That's much more to write up and perform, so I wouldn't really advise for this, unless you want the extra challenge. :)

About your related problem: Variables within "..." cannot get interpolated. In Smarty you'd need to try include file="inc/menu/`$staticpage_pagetitle`.inc" instead, I think.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Eni
Regular
Posts: 62
Joined: Thu Jan 27, 2005 10:47 pm
Location: Münster, Germany

Re: Image by page alias?

Post by Eni »

Thank you. I got the custom image now working perfectly :D

The menu still won't work. I tried this now:
{elseif $category_info.category_name}
{include file="inc/menu/`$category_info.category_name`.inc"}
That's what you meant, right? :?

~eni
Sorry, I'm Late. But I Got Lost On The Road Of Life.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Image by page alias?

Post by garvinhicking »

Hi!

Yeah, I was thinking about that. Did you try instead of a include to write:
{elseif $category_info.category_name}
Including"inc/menu/{$category_info.category_name}.inc"
{include file="inc/menu/`$category_info.category_name`.inc"}
Just to see if it's branching to the right place?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
marilynwinkler
Posts: 1
Joined: Tue Nov 19, 2019 11:39 am

Re: Image by page alias?

Post by marilynwinkler »

write my essay pro
Problem: The images load very slow and the "random" doesn't work well. It takes a couple of refreshes to get another image. That's why, instead of random, I'd like to call the images by page alias (category AND static pages). So when static page "profile" is called, the image "profile.png" would be load. When category "education" is called, the image "education.png" is called. When no alias matches, a fallback image is called.
I've though of plugin serendipity_event_categorytemplates at once. This plugin will help to create and use one template per category instead of writing lines of code which can look bulky at the end.
Post Reply