PHP if function joomla no work - php

Hello everyone and thank you in advance that I will answer. I have this problem, I want to see the second page where I find a link that takes me home page blog if in other categories.
I developed this little code:
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php $link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53" ?>
<?php $homeblog = "Blog" ?>
<?php $doc = JFactory::getDocument(); ?>
<?php $page_title = $doc->getTitle(); ?>
<?php echo $page_title; ?>
<?php if ($page_title != $homeblog) ?>
<?php echo "<a href='".$link_address."'>Home Blog</a>"; ?>
<?php endif; ?>
<?php echo $this->escape($this->params->get('page_title')); ?>
Unfortunately although not error the result is the same, or as if what I wrote was invisible. In homepage obviously sees the home page link (and that is the rule I)

Your code is missing a colon at the end of if statement.
Change
if ($page_title != $homeblog)
To
if ($page_title != $homeblog):
Also dont use <?php and ?> every line. You can have the code like this
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php
$link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53";
$homeblog = "Blog";
$doc = JFactory::getDocument();
$page_title = $doc->getTitle();
echo $page_title;
if ($page_title != $homeblog):
echo "<a href='".$link_address."'>Home Blog</a>";
endif;
echo $this->escape($this->params->get('page_title'));
?>

Related

CMS block only on first category page

I'm using Magento 1.9 and struggling on one thing.
I have a CMS block in my category page but I want it to show only on the first page! So if I scroll down and move to page 2 on the same category I don't want to see that CMS block again.
I tried to put this code in the CMS block... but it ignores me
(category-accordion.accordion is the main div of the CMS block)
<script>
if (window.location.href.indexOf("?p=") >-1)
{document.getElementsByClassName('category-accordion accordion')[0].display='none';}
// ]]></script>
Any idea?
EDIT:
tried the following code on the category page:
<?php if($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif($this->isMixedMode() && (strpos($_SERVER['REQUEST_URI'], '?=p') !== true)): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>
<?php elseif($this->isMixedMode() && (strpos($_SERVER['REQUEST_URI'], '?=p') !== false)): ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
<?php echo $this->getProductListHtml() ?>
<?php endif; ?>
you can set condition in Category View Template catalog\category\view.phtml.
<?php
$currentPage = (int) $this->getRequest()->getParam('p', 1);
if($currentPage <= 1) {
echo $this->getCmsBlockHtml()
} ?>
try this.
<script>
if (window.location.href.indexOf("?p=") >-1)
{
jQuery('.category-accordion.accordion').hide();
}
</script>

display text based on category in wordpress

how can i solve the following problem. Basically I want to show different sub headings based on the wordpress category being used.
this is the following code:
$categ = the_category(' ');
if($categ == 'News'){
$second_header = " secondry header displayed here";
}else{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Right now this is not working, instead of checking against the text 'news' is there any way to check against the category id?
thanks in advance.
You can use the following to store the current category id:
<?php $catID = the_category_ID($echo=false);?>
The echo false stops any echo on the page and stores the variable. You can then do the following:
<?php
$categ = the_category_ID($echo=false);
if($categ == 1)
{
$second_header = " secondry header displayed here";
}
else
{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Alternatively to this you could also use the following (as I believe the_category_ID is now deprecated http://codex.wordpress.org/Function_Reference/the_category_ID):
$categories = get_the_category();
$categ = $categories[0]->cat_ID;
if($categ == 1)
{
$second_header = " secondry header displayed here";
}
else
{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Different Text on some Category Pages:
<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages,
I could be left blank</p>
<?php endif; ?>
if you need category id you will need to first get category through <?php get_the_category_by_ID( $cat_ID ); ?>
Because the_category_ID is deprecated, then you can do the same with some modification.
More here - http://codex.wordpress.org/Category_Templates

Magento PHP if statement "load both blocks" , else load only one?

maybe it is something simple but i am not really good with php
With this code i am able to load the static blocks styled in top of category in Magento and the subcategories in the bottom when the top category has child
What i am trying to do is that when there is no child category it should only load the block
otherwise because of styling it will hold the place that the subcat had position.
Please have a look on my code and maybe you understand:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<div class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></div>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
$_catHtml = $this->getChildHtml('catalog.inline.subcat');
?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
// load the blocks styled with ul and il backgrounds
<ul class="inline-categories">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId( $this->getCurrentCategory()->getLandingPage() )->toHtml() ?>
<?php foreach ($_categories as $_category): ?>
<li<?php if($_i == 1):?> class="first"<?php endif ?>><a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>>
<?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)</li>
<?php endforeach ?>
<?php endif; ?>
</ul>
// here i need something like an "else" because the if($count) allready understand that this is not on count so should only load this that is without style //
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId( $this->getCurrentCategory()->getLandingPage() )->toHtml() ?>
//end of this else thing, now should only load the cms/block alone without anything / end of page we are done...
You can use PHP's if/else statements like this:
<?php if ($_count): ?>
stuff if $_count is non-zero
<?php else: ?>
other stuff if $_count is zero
<?php endif; ?>

How to add "tags" in joomla 3.x blog layout

I would like to add the article tags in my blog layout in joomla 3.x.
I overwrote the joomla layout files and tried to add the code below in blog_style_default_item_title.php as it is in article
<?php if ($params->get('show_tags', 1) && !empty($this->item->tags)) : ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
<?php endif; ?>
but it did not work. I guess variable name is not the good one. Any ideas?
My knowledges in php language are pretty weak but I had a look and tried a few think.
I finaly got something by adding code below in /com_content/category/blog_items.php
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
but i would like to add "tags" on the title line so in blog_style_default_item_title.phpfile
<?php
defined('_JEXEC') or die;
// Create a shortcut for params.
$params = $displayData->params;
$canEdit = $displayData->params->get('access-edit');
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.framework');
?>
<?php if ($params->get('show_title') || $displayData->state == 0 || ($params->get('show_author') && !empty($displayData->author ))) : ?>
<div class="page-header">
<?php if ($params->get('show_title')) : ?>
<h2>essai
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<?php echo $this->escape($displayData->title); ?></a>
<?php else : ?>
<?php echo $this->escape($displayData->title); ?>
<?php endif; ?>
</h2>
<?php endif; ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
<?php if ($displayData->state == 0) : ?>
<span class="label label-warning"><?php echo JText::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
But i have a error???
Here is how they are added to individual weblinks
<?php $tagsData = $item->tags->getItemTags('com_weblinks.weblink', $item->id); ?>
<?php if ($this->params->get('show_tags', 1)) : ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($tagsData); ?>
<?php endif; ?>
What you would want to do is something similar but for com_content.article and make sure the $item and $this->params references match what you have.
Here a picture of the design I would like
And he below the way the page id made of (as i understood it)
in blog_item.php there is this line which call the
...
<?php echo JLayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>
....
and so in blog_style_default_item_title.php
....
<div class="page-header">
<?php if ($params->get('show_title')) : ?>
<h2>essai
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<?php echo $this->escape($displayData->title); ?></a>
<?php else : ?>
Did I make a mistake??

Website Title Help

I'm working on adjusting my site title in Wordpress. I want my site title to admit the "Home >>" text from the title only on the homepage. Here is the code that i'm working with:
<title><?php if ( is_home() ) { ?> <?php } ?> <?php echo ucwords(wp_title('',false)); ?> » <?php echo ucwords(get_bloginfo('name')); ?> </title>
As i'm new to php, I'm trying decypher the coding. Would an if-else statement serve better?
<title><?php if ( is_home() )
echo "Blah blah blah";
else
echo "<?php echo ucwords(wp_title('',false)); ?>
» <?php echo
ucwords(get_bloginfo('name')); ?>";
?></title>
{ ?> <?php } ?>
<?php echo ucwords(wp_title('',false)); ?> » <?php echo ucwords(get_bloginfo('name')); ?>
</title>
I would greatly appreciate your opinion. My website is http://www.merrimentdesign.com
<title>
<?php if ( is_home() ) { ?> Home title, you don't need to echo something <?php } ?>
<?php echo ucwords(wp_title('',false)); ?> »
<?php echo ucwords(get_bloginfo('name')); ?>
</title>
Edit:
<title>
<?php
if ( is_home() ) { //I'm in the homepage
?>
Home title, you don't need to echo something
<?php
}else{ //every page but homepage
echo ucwords(wp_title('',false)) . '»' . ucwords(get_bloginfo('name'));
}
?>
</title>
An inline comparison would serve you well
<title>
<?php
echo (ishome()? "isHome evaluated to true": "isHome evaluated to false");
?>
</title>
Additionally nested PHP tags will not work and will simply throw errors.
IE
<?PHP
//everything in here is already php, if you add this:
echo "echo <?php doSomething(); ?>";
?>
Will not work because the ?> tag within your "echo" statement will be treated by PHP as the end of the PHP code block, not a string literal.
Instead of
echo "<?php echo ucwords(wp_title('',false));
just do
echo ucwords(wp_title('',false));
You can't echo PHP tags and have them be executed as PHP code.
That's what I do in my blog. But it won't work like it is - change it to:
<title><?php if ( is_home() )
echo "Blah blah blah";
else
echo ucwords(wp_title('',false)); ?>
»
<?php echo ucwords(get_bloginfo('name')); ?></title>

Categories