Show image "page_id.jpg" on page with matching page_id

erpe0812

@Argos

I am sure Ruud will add this to the droplet library.

@crnogorac081
It is only my impression and I want to let you know what I think about your posts.
But you can act in this forum as you like, but I personally would prefer those people, who benefit a lot from this forum to give some help back to the community, maybe by taking over a special task. As you know help is needed in many ways.

rgds

erpe

Argos

Michael, thanks for the rewrite into a droplet! I hope some admin will add it to AMASP. It can aslo be added as a regular snippet as well.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

crnogorac081

For all the time I am with WB, I tried to contribute by testing the modules and posting the bugs I found and coments. Also, if I see that someone has some problem here, and after few posts he or she finds the solution,I think that it is the best for all WB users to post the solution and not just to say "oh, I found the solution myself, thank you all.. " and close the post on the subject. My idea is to encourage those people to write down that solution, to update/create new module/snipet/droplet.. if you see there something you don't like, I will revoke myself and not write anything more on the forum.
Web developer

erpe0812

@crnogorac081

Many people who answer questions have no coding skills (like you and me), but there are not only questions, where coding skills are needed.
But if you want your questions to be answered (more than 150 posts) you should start helping other people too.
This is how such projects work  :wink:.

There is a lot of work to be done.
If you want to get a task please fill this form:
http://start.websitebaker2.org/en/join-the-team.php

rgds

erpe

crnogorac081

#9
@erpe

Unfortunatelly, you are right :) I am not coder :( that is my major problem :((((

------

btw, I have one site behind me, so I can share the template code :))
Web developer

BlackTiger

Such a droplet is no big mystery. Just return the code you want to replace. So the easiest way of building a droplet to replace the code of Argos is:


if (file_exists("".WB_PATH."/templates/".TEMPLATE."/pagepics/".PAGE_ID.".jpg") )
{
$str = "<img src=\"".TEMPLATE_DIR."/pagepics/".PAGE_ID.".jpg\" title=\"".PAGE_TITLE."\" alt=\"".PAGE_TITLE."\">\n";
}
else
{
$str = "<div class=\"pagepics\"><img src=\"".TEMPLATE_DIR."/pagepics/default.jpg\" title=\"".PAGE_TITLE."\" alt=\"".PAGE_TITLE."\"></div>\n";
}
return $str;


The droplet I use only returns the img-tag, but you can define alt, width and height:


$h = $w = $a = "";
if (isset($height)) $h = "height:".$height."px; ";
if (isset($width)) $w = "width:".$width."px; ";
if (isset($alt)) $a = 'alt="'.$alt.'" ';
$t = 'title="'.PAGE_TITLE.'" ';
return '<img src="'.WB_URL.MEDIA_DIRECTORY.'/pages/'.PAGE_ID.'.jpg" style="'.$w.$h.'" '.$a.$t.'/>';


Example:

[[DropletName?alt=Alternate text&width=300&height=225]]


regards
Michael

erpe0812

@crnogorac081

are you willing to share anything?
As I see you have more than 150 posts.

Anytime I read your posts you want to get something.

Have you answered just one question in the forum or have you shared something?

Or am I wrong?

rgds

erpe

PS: this forum is that good because many people are willing to answer posts and share tricks, knowledge and code.

crnogorac081

@BlackTiger

You said you have this as a droplet.. Cah you please share the code..

Cheers
Web developer

Argos

Thanks Michael, that works fine! Actually I made it a bit better by adding a default image option, and a title tag.


<?php
if (file_exists("".WB_PATH."/templates/".TEMPLATE."/pagepics/".PAGE_ID.".jpg") )
{
echo 
"<img src=\"".TEMPLATE_DIR."/pagepics/".PAGE_ID.".jpg\" title=\"".PAGE_TITLE."\" alt=\"".PAGE_TITLE."\">\n";
}
else
{
echo 
"<div class=\"pagepics\"><img src=\"".TEMPLATE_DIR."/pagepics/default.jpg\" title=\"".PAGE_TITLE."\" alt=\"".PAGE_TITLE."\"></div>\n";
}
?>



I think it's a nice addition to the snippets section on AMASP, by the way... Suggested name: PagePic. Or it could be turned into a droplet maybe (I tried, but failed).
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

BlackTiger

Sorry - the former code was not tested. The problem is the constant TEMPLATE_DIR - it is a URL and no directory like its name suggests. It should better be named TEMPLATE_URL. :)

The following code should work better:

<?php
if (file_exists("".WB_PATH."/templates/".TEMPLATE."/pagepics/".PAGE_ID.".jpg") )
{
echo 
"<img src=\"".TEMPLATE_DIR."/pagepics/".PAGE_ID.".jpg\" alt=\"".PAGE_TITLE."\">\n";
}
?>



I'm using similar code as a droplet on one of my sites - this makes later adjustments easier.

regards
Michael

Argos

Yes, but the funny thing is: that doesn't work. I tried that myself, because it seemed to be the most logical. As I am no coder, and just copy/paste stuff from other snippets I don't understand what's the problem and why that doesn't work...
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

BlackTiger

If I understand your question, you want something like:

<?php
if (file_exists("".TEMPLATE_DIR."/pagepics/".$page_id.".jpg") ) 

echo 
"<img src=\"".TEMPLATE_DIR."/pagepics/".$page_id.".jpg\" alt=\"".PAGE_TITLE."\">\n";
}
?>


regards
Michael

Argos

I use this code snippet for showing images with format "page_id.jpg" on pages that match the page_id.

<?php
if (file_exists("".WB_PATH."/templates/simple/pagepics/".$page_id.".jpg") ) 

echo 
"<img src=\"".TEMPLATE_DIR."/pagepics/".$page_id.".jpg\" alt=\"".PAGE_TITLE."\">\n";
}
?>


So in the template I put the code, and in the template directory "simple/pagepics" I have a number of images with names that match the pages where I want to show them. Works nicely, but to make it more generally usable, I want to change the reference to the template (in thsi case the Simple template), into code. I tried all kinds of things, but it doesn't work. I am no coder, and I don't have clue what to do. Anyone can give me a hand please?
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!