Making an image have a link - php

I`m new to this website and I was hoping to get my first question out and get some feedback on my issue.
I am creating a "slider" which you can find here: http://complusoft.net/demo-catarroja2/es/ (at the very beginning of the page) and i`m trying to make the images which pass through the slide to be a link.
Here you can find the code which I have done:
<?php foreach ($items as $key=>$item): ?>
<?php if($params->get('itemImage') && isset($item->image)): ?>
<a class="moduleItemTitle" href="<?php echo $item->link; ?>">
<img src="<?php echo $path1;?>?src=<?php echo $item->image;?>&w=635&h=386&zc=1&q=100" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" title="#htmlcaption<?php echo $key;?>"/>
</a>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php foreach ($items as $key=>$item): ?>
<div id="htmlcaption<?php echo $key;?>" class="nivo-html-caption">
<?php if($params->get('itemTitle')): ?>
<!--<h2><a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a></h2>-->
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemIntroText')): ?>
<div class="description-slider2">
<p><?php echo $item->introtext; ?></p>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
Ive looked around the internet and besides my own knowledge I know this should be the correct way besides the point that this is simple HTML I believe, I may be wrong please correct me if so.

Related

the_permalink not working? wp_list_pages

I'm trying to make wp list pages with thumbnails and other good stuff. But when i add the_permalink to my titles thumbnails etc and click on them, they are just refreshing the parent page and not getting the title(page) url. I'll insert what I have maybe someone knows how to fix it? Will be happy for any help ! THANKS
What I have
<div id="archive-thumbnails-listing" >
<?php $pages = get_pages(array('child_of' => 352)); ?>
<?php foreach ($pages as $page): ?>
<div class="thumb22">
<div class="thumb20"><a href="<?php the_permalink(); ?>">
<?php echo get_the_post_thumbnail($page->ID, 'full'); ?></a></div>
<div class="thumb19"><?php echo $page->post_title; ?></div>
</div>
<?php endforeach; ?>
</div>
try this: echo get_the_permalink($page->ID);
<div class="thumb19"><?php echo $page->post_title; ?></div>
</div>

Joomla! Need to make linkable banner images with Camera Slideshow

Need to make linkable images with Camera Slideshow. url must be received from Url_A in material.
in _item.php
<div class="camera-item" data-src="<?php echo htmlspecialchars($images->image_intro); ?>">
I tried to do
<?php $urls = json_decode($item->urls); ?>
<a href="<?php echo $urls->urla;?>">
<div class="camera-item" data-src="<?php echo htmlspecialchars($images->image_intro); ?>">
</div></a>
but got error. Help to novice please! and sorry for bad english :)
21.08
Full code of _item.php with some changes
<?php
defined('_JEXEC') or die;
$images = json_decode($item->images);
$urls = json_decode($item->urls);
$slider_img = htmlspecialchars($images->image_intro);
?>
<div class="camera-item" rel="<?php echo $urls->urla;?>" data-src="<? echo $slider_img; ?>">
<?php if ($params->get('show_caption')): ?>
<div class="camera_caption <?php echo $params->get('captionEffect'); ?>">
<?php $item_heading = $params->get('item_heading', 'h4'); ?>
<?php if ($params->get('item_title')) : ?>
<<?php echo $item_heading; ?> class="slide-title<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($params->get('link_titles') && $item->link != '') : ?>
<a href="<?php echo $item->link;?>">
<?php echo $item->title;?></a>
<?php else : ?>
<?php echo $item->title; ?>
<?php endif; ?>
</<?php echo $item_heading; ?>>
<?php endif; ?>
<?php if (!$params->get('intro_only')) :
echo $item->afterDisplayTitle;
endif; ?>
<?php echo $item->beforeDisplayContent; ?>
<?php echo $item->introtext; ?>
<?php if (isset($item->link) && $item->readmore != 0 && $params->get('readmore')) :
echo '<a class="readmore" href="'.$item->link.'">'.$item->linkText.'</a>';
endif; ?>
</div>
<?php endif; ?>
</div>
I got url to atribute rel but still can't make clickable images :(
In firebug
<div id="camera-slideshow" class="camera_wrap" style="height: 755px;">
<div class="camera_fakehover">
<div class="camera_src camerastarted camerasliding">
<div class="camera-item" data-src="images/slide1.jpg" rel="/index.php/urla"> </div>
<div class="camera-item" data-src="images/slide2.jpg" rel="/index.php/urla"> </div>
<div class="camera-item" data-src="images/slide3.jpg" rel=""> </div>
</div>
source code
<div class="camera-item" rel="/index.php/urla" data-src="images/slide1.jpg">
<div class="camera_caption fadeIn">
<div class="txt1">some text</div>
<div class="txt2">some text</div>
</div>
</div>

How to use a [slideshow] image as a link

I'm having an issue using images from a Slideshow as links.
This is my code:
<div class="slider-wrapper theme-default sl-2">
<div id="slider-2" class="nivoSlider-2" >
<?php foreach ($items as $key=>$item): ?>
<?php if($params->get('itemImage') && isset($item->image)): ?>
<a class="moduleItemTitle" href="<?php echo $item->link; ?>">
<img src="<?php echo $path1;?>?src=<?php echo $item->image;?>&w=635&h=386&zc=1&q=100" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" title="#htmlcaption<?php echo $key;?>"/>
</a>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php foreach ($items as $key=>$item): ?>
<div id="htmlcaption<?php echo $key;?>" class="nivo-html-caption">
<?php if($params->get('itemTitle')): ?>
<!--<h2><a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a></h2>-->
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemIntroText')): ?>
<div class="description-slider2">
<p><?php echo $item->introtext; ?></p>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
I pass through the "a" tag the $item->link parameter which returns these two strings since the slideshow only contains two images:
string(51) /demo-catarroja2/es/campanas/cavi-catarroja-virtual
&
string(49) /demo-catarroja2/es/campanas/plan-de-ayuda-social
If I inspect the element with a web browser it shows this:
<a class="moduleItemTitle" href="/demo-catarroja2/es/campanas/plan-de-ayuda-social">
<img src="http://complusoft.net/demo-catarroja2/templates/onews/html/thumb.php?src=/demo-catarroja2/media/k2/items/cache/9c2fe6cb8c357cf6d57c8926869c1003_XL.jpg&w=635&h=386&zc=1&q=100" alt="Plan de Ayuda social 2013" title="#htmlcaption1"/>
</a>
This image is obviously inside the a tag but its acting as a link, why could this be?
You can check out the site here:
The slideshow is on the main page up top.

PHP (Kirby): redirect gallery to subfolder

Hi I've been working with Kirby. I'm a complete beginner in PHP but managed to get a lot done. Just need some help with the gallery.
On the homepage a single image is displayed as thumbnail:
<?php foreach($articles as $article): ?>
<li class="<?php foreach(str::split($article->tags()) as $tag): ?><?php echo $tag ?> <?php endforeach ?>">
<?php foreach($article->images() as $image): ?><?php echo thumb($image, array('width' => 300, 'quality' => 70)) ?><?php endforeach ?><p><?php echo html($article->title()) ?></p>
</li>
<?php endforeach ?>
On the article page I'd like to have a gallery.
The gallery snippet:
<?php if($page->hasImages()): ?>
<ul class="gallery">
<?php foreach($page->images() as $image): ?>
<li>
<img src="<?php echo $image->url() ?>" width="<?php echo $image->width() ?>" height="<?php echo $image->height() ?>" alt="<?php echo $image->name() ?>" />
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
Using Kirby, makes me store all the article items in one folder. But if I do this, and use the code mentioned above, all the images from the gallery also show up as thumbnails on the homepage.
I guess the best would be to edit the gallery snippet so it can grab images from a subfolder. But how?
Thank you for your help!
One solution to this is to name the file you wanna have displayed on the front page something like front.jpg. You can then directly access this image with $page->images()->find('front.jpg').
So you get this:
<?php foreach($articles as $article): ?>
<li class="<?php foreach(str::split($article->tags()) as $tag): ?><?php echo $tag ?> <?php endforeach ?>">
<a href="<?php echo $article->url() ?>" title="<?php echo html($article->title()) ?>">
<?php echo thumb($article->images()->find('front.jpg'), array('width' => 300, 'quality' => 70)) ?>
<p><?php echo html($article->title()) ?></p>
</a>
</li>
<?php endforeach ?>
(Note, that you have to remove the inner foreach-loop, because you're only displaying one image.)
The gallery snippet stays the same.
Here try:
<?php foreach($page->image()->yaml() as $image): ?>
<?php if($img = $page->image($image)): ?>
<img src="<?= $img->url() ?>" alt="<?= $page->title()->html() ?>" width="100%" height="100%" />
<?php endif ?>
<?php endforeach ?>

joomla/k2 php template overrides

Really need some help after many hours of banging head against a brick wall!
Basically I have a Joomla News page made in the K2 component. The page would have the top story, the next two, then the next four and the next four after that all with their own class so they can be styled differently for emphasis (like most news websites).
So there would be one row of one column - main news (with items image and text cut off after about 150 words with a 'read more')
second row - two columns - next two news pieces (with items image and text cut off after about 150 words with a 'read more')
third row - four columns - next four news pieces (with items image and text cut off after about 150 words with a 'read more')
fourth row - one column of eight links (no image just the title linked)
This is the file I'm trying to amend:
<?php
// no direct access
defined('_JEXEC') or die;
$selectedFilters=$params->get('extraFieldsSelect'); //get selected fields in module params
?>
<div id="k2ModuleBox<?php echo $module->id; ?> k2FiltrifyContainer" class="k2Filtrify k2ItemsBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
<?php if($params->get('itemPreText')): ?>
<p class="modulePretext"><?php echo $params->get('itemPreText'); ?></p>
<?php endif; ?>
<!--Filtrify Placeholder-->
<div id="k2FiltrifyPlaceHolder"></div>
<?php //set placeholder, if LEGEND is the selected callback method
if($placeholder == 'legend'): ?>
<!--Filtrify legend placeholder-->
<div id="legend"><i><?php echo JText::_('K2_VIEWING_ALL'); ?></i></div>
<?php endif; ?>
<?php //set placeholder, if PAGINATION is the selected callback method
if($placeholder == 'pagination'): ?>
<!--Filtrify pagination placeholder-->
<div id="pagination"></div>
<?php endif; ?>
<?php if(count($items)): //Filtrify Container?>
<ul id="k2FiltrifyContainer">
<p>
<?php foreach ($items as $keyItem=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($keyItem+1)%($params->get('num_columns'))==0) || count($items)<$params->get('num_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<li class="itemContainer<?php echo $lastContainer; ?>" <?php echo (count($items)==1) ? '' : ' style="width:'.number_format(100/$params->get('num_columns'), 1).'%;"'; ?>
<?php
if( count($item->extra_fields) && $selectedFilters != ''): //check if there are extrafields and selected fields?>
<?php foreach ($item->extra_fields as $key=>$extraField): //adding extrafields as data parameter?>
<?php if(in_array($extraField->id,(array)$selectedFilters, TRUE)) : ?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яa-zA-Z?-??-?sctzlldSCTZLD]/ui", "_", $extraField->name); ?>="<?php echo $extraField->value; //set the values, and remove special chars?>"
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if($params->get('showCatFilter')==1): //check for param - show category filter?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_CATEGORIES')); ?>="<?php echo $item->categoryname;?>"
<?php endif; ?>
<?php if($params->get('showTagFilter')==1): //check for param - show tag filter?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_TAGS')); ?>="<?php foreach ($item->tags as $tag): ?><?php echo $tag->name; ?>, <?php endforeach; ?>"
<?php endif; ?>
>
</p>
<p>
<?php if(isset($item->event->BeforeDisplay)): ?>
<!-- Plugins: BeforeDisplay -->
<?php echo $item->event->BeforeDisplay; ?>
<?php endif; ?>
<!-- K2 Plugins: K2BeforeDisplay -->
<?php echo $item->event->K2BeforeDisplay; ?>
<?php if($params->get('itemAuthorAvatar')): ?>
<a class="k2Avatar moduleItemAuthorAvatar" rel="author" href="<?php echo $item->authorLink; ?>">
<img src="<?php echo $item->authorAvatar; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
</a>
<?php endif; ?>
<?php if($params->get('itemTitle')): ?>
<a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>
<?php endif; ?>
<?php if($params->get('itemAuthor')): ?>
</p>
<div class="moduleItemAuthor">
<?php echo K2HelperUtilities::writtenBy($item->authorGender); ?>
<?php if(isset($item->authorLink)): ?>
<a rel="author" title="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" href="<?php echo $item->authorLink; ?>"><?php echo $item->author; ?></a>
<?php else: ?>
<?php echo $item->author; ?>
<?php endif; ?>
<?php if($params->get('userDescription')): ?>
<?php echo $item->authorDescription; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if(isset($item->event->AfterDisplayTitle)): ?>
<!-- Plugins: AfterDisplayTitle -->
<?php echo $item->event->AfterDisplayTitle; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplayTitle -->
<?php echo $item->event->K2AfterDisplayTitle; ?>
<?php if(isset($item->event->BeforeDisplayContent)): ?>
<!-- Plugins: BeforeDisplayContent -->
<?php echo $item->event->BeforeDisplayContent; ?>
<?php endif; ?>
<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php echo $item->event->K2BeforeDisplayContent; ?>
<?php if($params->get('itemImage') || $params->get('itemIntroText')): ?>
<div class="moduleItemIntrotext">
<?php if($params->get('itemImage') && isset($item->image)): ?>
<a class="moduleItemImage" href="<?php echo $item->link; ?>" title="<?php echo JText::_('K2_CONTINUE_READING'); ?> "<?php echo K2HelperUtilities::cleanHtml($item->title); ?>"">
<img src="<?php echo $item->image; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>"/>
</a>
<?php endif; ?>
<?php if($params->get('itemIntroText')): ?>
<?php echo $item->introtext; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemExtraFields') && count($item->extra_fields)): ?>
<div class="moduleItemExtraFields">
<b><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></b>
<ul>
<?php foreach ($item->extra_fields as $extraField): ?>
<?php if($extraField->value): ?>
<li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="moduleItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
<span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<div class="clr"></div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemVideo')): ?>
<div class="moduleItemVideo">
<?php echo $item->video ; ?>
<span class="moduleItemVideoCaption"><?php echo $item->video_caption ; ?></span>
<span class="moduleItemVideoCredits"><?php echo $item->video_credits ; ?></span>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if(isset($item->event->AfterDisplayContent)): ?>
<!-- Plugins: AfterDisplayContent -->
<?php echo $item->event->AfterDisplayContent; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplayContent -->
<?php echo $item->event->K2AfterDisplayContent; ?>
<?php if($params->get('itemDateCreated')): ?>
<span class="moduleItemDateCreated"><?php echo JText::_('K2_WRITTEN_ON') ; ?> <?php echo JHTML::_('date', $item->created, JText::_('K2_DATE_FORMAT_LC2')); ?></span>
<?php endif; ?>
<?php if($params->get('itemCategory')): ?>
<?php echo JText::_('K2_IN') ; ?> <a class="moduleItemCategory" href="<?php echo $item->categoryLink; ?>"><?php echo $item->categoryname; ?></a>
<?php endif; ?>
<?php if($params->get('itemTags') && count($item->tags)>0): ?>
<div class="moduleItemTags">
<b><?php echo JText::_('K2_TAGS'); ?>:</b>
<?php foreach ($item->tags as $tag): ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if($params->get('itemAttachments') && count($item->attachments)): ?>
<div class="moduleAttachments">
<?php foreach ($item->attachments as $attachment): ?>
<a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if($params->get('itemCommentsCounter') && $componentParams->get('comments')): ?>
<?php if(!empty($item->event->K2CommentsCounter)): ?>
<!-- K2 Plugins: K2CommentsCounter -->
<?php echo $item->event->K2CommentsCounter; ?>
<?php else: ?>
<?php if($item->numOfComments>0): ?>
<a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">
<?php echo $item->numOfComments; ?> <?php if($item->numOfComments>1) echo JText::_('K2_COMMENTS'); else echo JText::_('K2_COMMENT'); ?>
</a>
<?php else: ?>
<a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">
<?php echo JText::_('K2_BE_THE_FIRST_TO_COMMENT'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if($params->get('itemHits')): ?>
<span class="moduleItemHits">
<?php echo JText::_('K2_READ'); ?> <?php echo $item->hits; ?> <?php echo JText::_('K2_TIMES'); ?>
</span>
<?php endif; ?>
<?php if($params->get('itemReadMore') && $item->fulltext): ?>
<a class="moduleItemReadMore" href="<?php echo $item->link; ?>">
<?php echo JText::_('K2_READ_MORE'); ?>
</a>
<?php endif; ?>
<?php if(isset($item->event->AfterDisplay)): ?>
<!-- Plugins: AfterDisplayContent -->
<?php echo $item->event->AfterDisplay; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplay -->
<?php echo $item->event->K2AfterDisplay; ?>
<div class="clr"></div>
</li>
<?php if((($keyItem+1)%($params->get('num_columns'))==0) && (($placeholder != 'pagination'))) : ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<li class="clearList"></li>
</ul>
<?php endif; ?>
<?php if($params->get('itemCustomLink')): ?>
<a class="moduleCustomLink" href="<?php echo $params->get('itemCustomLinkURL'); ?>" title="<?php echo K2HelperUtilities::cleanHtml($itemCustomLinkTitle); ?>"><?php echo $itemCustomLinkTitle; ?></a>
<?php endif; ?>
<?php if($params->get('feed')): ?>
<div class="k2FeedIcon">
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&format=feed&moduleID='.$module->id); ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?>">
<span><?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?></span>
</a>
<div class="clr"></div>
</div>
<?php endif; ?>
</div>
Like I say, I've tried and tried to make this template work, but have got nowhere!
You try it with wrong file! This file belongs to Filtrify Module!
You must:
set as template for category "default"
edit K2 native category settings,
edit K2 native category item settings,
edit K2 native
item settings,
After you set all native K2 parameters, you must clone your default k2 template. Do it so:
go into components/com_k2/templates.
Copy all, what you see, locally.
Then create in you templates/your-template/html folder named com_k2.
Copy into it all, what you got befor from components/com_k2/templates.
Then duplicate folder named "default" and give them own name. This will be your K2 template for overrides.
Then go into K2 administration and change template of you category, which you set up befor, from default to the new name. Just now you can begin with template overrides, but ONLY inside of templates/your template/html/com_k2/your-k2-template. The files you need to override are category-item.php for category view and item.php for single item view.

Categories