I want to make the joomla articles intro image to behave like the read more, and the title link. So the user clicks the image, and the article loads.
I'm not an PHP expert but maybe this is the readmore links code:
<a href="<?php echo $this->item->readmore_link; ?>" class="button<?php echo $this->item->params->get('pageclass_sfx'); ?>">
<?php if ($this->item->readmore_register) :
echo JText::_('Register to read more...');
elseif ($readmore = $this->item->params->get('readmore')) :
echo $readmore;
else :
echo JText::_("Read Article");
endif; ?></a>
This is what i want to do with every intro image on my joomla site.
Thanks !
Just resolved it!
your way of thinking helped me. Thank you!
here's my code:
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>">
<?php
$images = json_decode($item->images);
if (isset($images->image_intro) and !empty($images->image_intro)) {
$imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />';
}
echo $this->item->introtext;
?>
</a>
for Joomla 2.5:
in your override for _item.php (Location: yourtemplate\html\mod_articles_news\item.php)
place the following line:
<?php if ($params->get('image')) : ?>
<?php $images = json_decode($item->images); ?>
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
<?php endif; ?>
<?php endif; ?>
Place it there where you would like it to show up
For example after:
<?php echo $item->beforeDisplayContent; ?>
Your intro image has become a link now.
the isset part, makes sure that if a viewer uses Internet Explorer, it doesn't show up a small red cross box.
Just for the information:
in blog_item.php you can find an example code how it's shown up in an article. Here you can also find the code for imagefloat etc.
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
So let me start by explaining what the code that you've posted above does. The entire block of code generates one link: there are a bunch of if statements that are determined based off some settings. For example, if you have set that people need to register in order to read more, the link will say "Register to read more..."
The part that we're interested in here, however, since we want to turn images into links, is the URL that we want the images to link to. This is right in the first line:
<a href="<?php echo $this->item->readmore_link; ?>"
so we know that the URL is provided dynamically thanks to $item->item->readmore_link and all this code is doing is echoing it into the HTML.
All that's left is to edit your Joomla template of the page on which you have your images (probably the same file you took this code from). It looks like this should be part of a greater PHP loop, which loops through all the posts. Somewhere above where you found this code, should be code for the intro image that goes along with that post.
I'm not sure what it'll look like, it could be a <img src="<? stuff here; ?> /> or it could be dynamically generated. Keep reading. If you're still not sure where to find it at the end, edit your post with the full code of the template where you got the above snipping from. Regardless of what it looks like, it is referred to as <WHATEVER IMAGE CODE YOU FOUND ABOVE> in the following step:
You have to wrap that image with "a" tags so that it looks like the following:
<WHATEVER IMAGE CODE YOU FOUND ABOVE>
That should do it. Let me know if you have any trouble, I'll be more than happy to make my post more specific if you can provide more detailed information, but I've tried to explain it well enough that you should be able to figure it out with a couple tries.
As you stated you are not a PHP expert, it sounds like your best bet will be to use a Joomla extension that has similar functionality to what you want.
I believe mod_minifrontpage will work for what you need. It allows you to display a list of articles, and it generates thumbnails for those articles based on the first image to be referenced.
There are article intro images in J, since 1.7.5 and now in latest 2.5.3
what you need is change the defaults for component_content,
you can do it 2 ways, editing views in yourinstall/components/com_content/views/
or use template overrides , you first need to know if your template IS using overrides otherwise if you edit component views in the component itself you will not see changes.
to verify this , go to
site_name/templates/template_name/html folder and check if there is folder name
com_content ,
if that is the case than your template is using overrides and any edits should be done trough there not through component
now to the actual code
this is in
components\com_content\views\featured\tmpl\default_item.php ( THIS I DEFAULT FRONTPAGE ARTICLE VIEW)
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
all you would need to do is wrap a element around IMG tag with readmore link like this
<a href="<?php echo $this->item->readmore_link; ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
DO NOT forget that if there is template override for com_content you wold need to edit the featured/default_item.php inside it
In Joomla 3.1, the intro_image layout has been moved to the layouts/joomla/content folder. In my situation, it is called from com_content/views/category/tmpl/blog_item.php like so:
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
I moved that file to my template/html/com_content/category/blog_item.php and then wrapped the call to JLayoutHelper like so:
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>">
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
</a>
If you have Gantry installed on Joomla 3.1, the overrides are in a different location. You will want to navigate to plugins/system/gantry/overrides/3.0/2.5/com_content/category/blog_item.php and wrap the intro image with the read more link code.
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>"><img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/></a>
Related
I am trying to shorten the url when the frontend is being changed to a different language.
I already managed to shorten it a bit through setting <?php echo $_lang->getCurrentUrl() ?> to <?php echo $_lang->getCurrentUrl(false) ?> but it still shows the $store=.
I just want my urls to be like that: domain.com/de and domain.com/en.
One possible solution is to change the your page/switch/languages.phtml file
Find the line that reads
echo $_lang->getCurrentUrl()
And replace with
echo $_lang->getCurrentUrl(false)
Option 2
Go to System -> Configuration -> Web -> URL Options and set the 'Add Shop Code to URLs' option to Yes
This will make the urls to the store appear like the following:
www.myshop.com/otherstore/
www.myshop.com/default/
To edit the names of your stores to be SEO friendly, go to System -> Manage Shops
Quelle: https://magento.stackexchange.com/questions/53386/magento-multistore-store-and-from-store-in-url/53426#53426
Assuming your store code are 'de' and 'en' for the said stores, you just have to adapt your configuration under
System > Configuration > Web > Add Store Code to URLs
<?php if(count($this->getStores())>1): ?>
<div class="language dropdown">
<div class="dropdown-toggle cover">
<!--<div class="icon" style="background-image:url(<?php echo $this->getSkinUrl().'images/flags/' . $this->htmlEscape(Mage::app()->getStore()->getName() .'.png'); ?>)"></div>-->
<div class="language-inner">
<div class="value">
<?php echo Mage::app()->getStore()->getName(); ?>
</div>
</div>
</div>
<div class="dropdown-menu left-hand" onchange="window.location.href=this.value">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<a href="<?php echo $_lang->getCurrentUrl(false) ?>" class="currency_icon<?php if($_lang->getId() == $this->getCurrentStoreId()):?> selected <?php endif; ?>">
<!--<span class="icon" style="background-image:url(<?php echo $this->getSkinUrl().'images/flags/' . $this->htmlEscape($_lang->getName() .'.png'); ?>)"></span>-->
<?php echo $this->htmlEscape($_lang->getName()); ?>
</a>
<?php endforeach; ?>
</div>
I'm learning Kirby CMS.
I have a page displaying a series of images, I'm unsure how to get the date the image was uploaded.
I think it is something to do with the $file variable?:
$file->modified($format=false)
the last modified timestamp
here is my php loop:
<?php if($page->hasImages()): ?>
<ul class="gallery">
<?php foreach($page->images() as $image): ?>
<div class="gallerySegment">
<h3 class="guidelineHead"><?php echo $image->title() ?></h3>
<p><?php echo $image->caption() ?></p>
<li><img src="<?php echo $image->url() ?>" width="<?php echo $image->width() ?>" height="<?php echo $image->height() ?>" alt="<?php echo $image->title() ?>" /></li>
</div>
<?php endforeach ?>
</ul>
<?php endif ?>
I think this isn't possible by default in kirby 1. You could use the php-function filetime().
In case of Kirby 2 you can write $file->modified($format = false) as in your proposal.
You should be able to simply do something like this within your loop.
<p>Uploaded at: <?php echo $image->modified('d. F Y'); ?></p>
This is available in Kirby 1 as well as in Kirby 2 as a single "image object" you have in your $image variable is always an extended "file object". That means you can use all file object methods on image objects as well.
If you need any information about how set the $format ('d. F Y'), you should have a look at PHPs date() function explanation
I'm trying to make an if-else-statement which works by going if there is a link print it around the name.
I have the below code which is almost there. However, the link is being printed above the text ranther than being an actual link.
<?php if( the_sub_field('corporate_link') ){ ?>
<a href="<?php the_sub_field('corporate_link'); ?>"
target="_blank"
title="<?php the_field('corporate_name'); ?>"><?php the_field('corporate_name'); ?></a>
<?php } else { ?>
<?php the_sub_field('corporate_name'); ?>
<?php } ?>
Any thoughts on how to make it link instead of printing the link if it`s there?
So what im looking to acheive is if there is a link print this
Coprate Name
If there isn't a link it just shows the corporate name.
use get_sub_field('corporate_link') instead of the_sub_field('corporate_link')
<?php
$corporate_link = get_sub_field('corporate_link');
$corporate_name = get_sub_field('corporate_name');
if( $corporate_link != '' ){ ?>
<a href="<?php echo $corporate_link; ?>"
target="_blank"
title="<?php echo $corporate_name; ?>"><?php echo $corporate_name; ?></a>
<?php } else { ?>
<?php echo $corporate_name; ?>
<?php } ?>
use get_sub_field() and get_field() instead of the_sub_field() and the_field()
I find this com_content/views/article/tmpl/default.php I created a template override and here is the code:
<?php if ($params->get('access-view')):?>
<?php if (isset($images->image_fulltext) && !empty($images->image_fulltext)) : ?>
<?php $imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext; ?>
<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image">
<img
<?php if ($images->image_fulltext_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
<?php endif; ?>
Before img tag how to form, modify this php code to be clickable the image to self url:
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>"> <img
Here is the resolution:
<a href="<?php echo JURI::root().$images->image_fulltext; ?>">
Now the image is "clickalble" to self url
JURI::root() > your webpage url (like: something.com)
$images->image_fulltext > in joomla 3.1 you can choose an image what is displayed when you click to readmore, ie when you read the full article, that image have an url, like: /images/stories/freshsite/something.jpg
This php code combines these two code, to be: something.com/images/stories/freshsite/something.jpg > when you click on the image, only this image will shows in you browser :)
I´m display a slider that get´s the images from custom field, now I need that the slider shows different images depending on the language (es - ca):
This is the code of the slider:
<a href="<?php the_field('slider_home_1_enlace') ?>">
<img src="<?php the_field('slider_home_1'); ?>">
</a>
So I´m creating a conditional tag to load images depending of the language of qtranslate plugin:
<?php
_e('<!--:es-->
<a href="<?php the_field('slider_home_1_enlace') ?>">
<img src="<?php <the_field('slider_home_1'); ?>">
</a>
<!--:-->
<!--:ca-->
<a href="<?php the_field('slider_home_1_enlace_ca') ?>">
<img src="<?php the_field('slider_home_1_ca'); ?>">
</a>
<!--:-->');
?>
I´m a php begginer so I see the problem maybe that the php is inside another php, because this way its not working, if i just put text between tags it works properly for the language.
Any ideas how to syntax this?
You need to check language first, using if - else
detect the language and store it to the variable named $language and then check the condition as below.
<?php
if(qtrans_getLanguage()=="es"){
?>
<a href="<?php the_field('slider_home_1_enlace'); ?>">
<img src="<?php the_field('slider_home_1'); ?>">
</a>
<?php
} else if(qtrans_getLanguage()=="ca"){
?>
<a href="<?php the_field('slider_home_1_enlace_ca'); ?>">
<img src="<?php the_field('slider_home_1_ca'); ?>">
</a>
<?php
}
?>
You can't have php-tags inside each other.
Use basic string concatenation to combine your strings: http://php.net/manual/en/language.operators.string.php
You can't use it that way. Compare: (I guess that the_field() returns the string ;))
<a href="'.the_field("slider_home_1_enlace").'">
<img src="'.the_field("slider_home_1").'" />
</a>
There are multiple mistakes. At first, you can't use the
'.(your things here).'
Second, theres a < in your fourth line and you forget to close your img-tag.
First, install the qTranslate Wordpress plugin.
Then, you can try this:
<?php
$slider_img_fields_langs = array(
'',
'ca',
'es',
);
$lang = qtrans_getLanguage();
if( !in_array( $lang, $slider_img_fields_langs ) );
$lang = '';
echo '
<a href="' . the_field( 'slider_home_1_enlace' . $lang ) . '">
<img src="' . the_field( 'slider_home_1' . $lang ) . '">
</a>';
?>