I'm having a doubt. What I'm not sure of is how I should segment/structure or implement PHP code into the HTML.
So far, I have structured the coding in following way, echoing out the HTML . But My code didnt work . I have tried to give 'Signout', while the session is present and 'sign-in', while the session is alive.
<ul>
<?php if($this->session->userdata('id') == '1')
echo '<li class="active"><a class="btn" href='.'"<?php echo base_url();?>'.'index.php/login/log_out">SIGN OUT </a></li>';
else
{
echo '<li class="active"><a class="btn" href='.'"<?php echo base_url();?>'.'index.php/welcome/login">SIGN IN / SIGN UP</a></li>';
} ?>
</ul>
Is it the correct way? where am i getting wrong.
I found a answer to the above structuring
1. The first thing i saved my view file inside the codeigniter to 'full_calendar.php' which was earlier as 'full_calendar.htm'
2. The second thing I structurally modified my code as follows:-
<ul><?php if($this->session->userdata('id') == '1')
echo '<li class="active"><a class="btn" href='.base_url().'index.php/login/log_out>SIGN OUT </a></li>';
else
{
echo '<li class="active"><a class="btn" href='.base_url().'index.php/welcome/login>SIGN IN / SIGN UP</a></li>';
} ?></ul>
And, I now understand that it is mis-match of single quotes and double quotes, which matters the most.
Related
I am trying to implement dynamic breadcrumbs in laravel with links. I successfully render the breadcrumbs but without links by following code.
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i>Marketplace</li>
#foreach(Request::segments() as $segment)
<li>
{{$segment}}
</li>
#endforeach
</ol>
But now i am facing issue with the urls. I am getting the current url of the route with all the decendents. Can someone please help me that how can I add links to the breadcrumbs ?
Thanks.
If I understand your issue correctly, you just need to fill in the URL of the link. This is untested but I think it should work.
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i>Marketplace</li>
<?php $segments = ''; ?>
#foreach(Request::segments() as $segment)
<?php $segments .= '/'.$segment; ?>
<li>
{{$segment}}
</li>
#endforeach
</ol>
This worked for me, tried in Laravel 5.4.*
Requirement for this code to work flawlessly: All URL's should have hierarchy pattern in your routes file
Below code will create crumb for each path -
Home >
<?php $link = "" ?>
#for($i = 1; $i <= count(Request::segments()); $i++)
#if($i < count(Request::segments()) & $i > 0)
<?php $link .= "/" . Request::segment($i); ?>
{{ ucwords(str_replace('-',' ',Request::segment($i)))}} >
#else {{ucwords(str_replace('-',' ',Request::segment($i)))}}
#endif
#endfor
So Breadcrumb for URL your_site.com/abc/lmn/xyz will be - Home > abc > lmn > xyz
Hope this helps!
Im not sure if you already got a solution for this, but i figured out a way to go about it on my project. It might come in handy for your implementation.
I ended up with either adding the whole url to the link or only the segment, which ofc is not desirable, so using array slice i start slicing from the 0 index in the array and only slice untill the current iteration of the loop, then implode the array into a string and then use URL::to to create the link.
<ol class="breadcrumb">
<li>
<i class="fa fa-home"></i>
HOME
</li>
#for($i = 2; $i <= count(Request::segments()); $i++)
<li>
<a href="{{ URL::to( implode( '/', array_slice(Request::segments(), 0 ,$i, true)))}}">
{{strtoupper(Request::segment($i))}}
</a>
</li>
#endfor
</ol>
As you will notice, I only start my iteration from 2 ($i = 2) as my app base url starts at /admin and i manually put my home Url in the first breadcrumb.
Again you might already have a solution, but throught this could work for people who do not want to add the package to get breadcrumbs.
I wrote a this code that can handle laravel resource ( index | edit | create ) routes dynamically:
Custom Breadcrumb => custom.blade.php
#php
$segments=[];
$l=count(Request::segments())-1
#endphp
#switch(Request::segments()[$l])
#case('edit')
#php
$l--;
$segments=array_slice(Request::segments(),0,$l);
$segments[]=$model->slug // Model that passed to this included blade file
#endphp
#break
#default
#php $segments=Request::segments() #endphp
#endswitch
#php
$link=''
#endphp
#foreach($segments as $sg)
#php $link.='/'.$sg #endphp
#if($loop->index<$l)
<li class="breadcrumb-item">
{{ucfirst($sg=='admin'?'home':$sg)}}
</li>
#else
<li class="breadcrumb-item active">
{{ucfirst($sg)}}
</li>
#endif
#endforeach
Use Custom Breadcrumb => example.balde.php
#include('admin.vendor.breadcrumb.custom',['model'=> $articles])
Just add slash / before any link to add decendents to domain name
like that
<a href="/YourLink" ></a>
I liked the solution offered by #rohankhude but it was not showing "/" after the first segment (marketplace). So here is a clean code.
<div class="breadcrumb">
<ul>
<li>
Home
</li>
<?php $link = "" ?>
#for($i = 1; $i <= count(Request::segments()); $i++)
#if($i < count(Request::segments()) & $i > 0)
<?php $link .= "/" . Request::segment($i); ?>
#if ($i == 1)
/ {{ ucwords(str_replace('-',' ',Request::segment($i)))}}
#else
{{ ucwords(str_replace('-',' ',Request::segment($i)))}}
#endif
#else
<a class="active">/ {{ucwords(str_replace('-',' ',Request::segment($i)))}}</a>
#endif
#endfor
</ul>
</div>
I am developing a blog using codeigniter, every thing works good like posts are being stored comments are being made likes also works the only problem is fetching the comments using codeigniter against each post. What i want to do is that i want to send id to controller of each id when page loads. Here is the screenshot to make it more clear how i am working.
Front end is like this
Now the code section:
1. Code on the blog page where all messages and posts are being shown
<div class="col-lg-11 col-md-10 col-sm-10 col-xs-9 post_message" id="getComments<?php echo $blog -> blog_id; ?>">
<p>
<?php echo $blog -> message; ?>
</p>
<span class="pull-left">
<small> Posted By: <?php echo $blog -> name; ?></small>
</span>
<!-- onclick="get_comments(this.id, '<?php //echo base_url('users/get_comments_total'); ?>')" id="<?php// echo $blog -> blog_id; ?>-->
<a>
<i class='fa fa-comment' aria-hidden='true'></i> Comments (<small> <?php echo $rows; ?> </small>)
</a>
<a onclick="update_like('<?php echo $blog -> blog_id; ?>', '<?php echo base_url('users/update_like'); ?>')">
<i class='fa fa-thumbs-up' aria-hidden='true'></i> Likes (<small><?php echo $blog -> likes; ?></small>)
</a>
<div class="result_id<?php echo $blog -> blog_id; ?>" style="display: block;float: left;width: 100%;"></div>
</div> <!-- End of post message -->
In the above code there is a line written in comments where on-click function is defined i want to pass each id on page load to controller instead of click and all this code is written in foreach loop.
Help me with this thing or tell if there is any better idea to achieve this. Please do see the image attached with this so that you can know easily how i want to display the comments. one hint is like FB comments.
What is $rows?
If the likes are working OK then you can use the same idea for the comments. Probably you have joined the likes table and that is why you have $blog -> likes;. You should join the comments table to the query and then use Comments (<small> <?php echo $blog->comments; ?> </small>).
If this does not work you should provide your query in the model and your database structure.
I’m hoping someone can help me with this problem I’ve been trying to solve for the past few days. I want to hide Magento’s Layered Navigation from the search engines entirely, but make it available to users. For SEO reasons, I don’t want to settle for NoFollowing all the links, or using noindex follow meta tags, or even blocking it entirely with Robots.txt. The most effective way of handling this would be only showing the layered Navigation to users with Cookies enabled, since Google doesn’t use cookies. The same effect could probably be achieved with JavaScript as well, but I’ve chosen the Cookie method.
So far I’ve managed to implement a crude piece of JS to check if cookies are enabled once the page has loaded (adapted from another thread on this forum). If cookies are enabled, it does nothing and layered nav displays, but if cookies are not enabled, I want to remove the “catalog.leftnav” block. I can’t for the life of me figure out how to do this from my JS script. All I’ve been able to achieve is removing the div element, or setting style.display to none etc., and while all of these techniques remove the links from the frontend, Google can still see them all. Here’s an example of the code I have so far in template/catalog/layer/filter.phtml
<div id="shop-by-filters">
<ol>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if ($_item->getCount() > 0): ?>
<?php echo $_item->getLabel() ?>
<?php else: echo $_item->getLabel() ?>
<?php endif; ?>
<?php if ($this->shouldDisplayProductCount()): ?>
(<?php echo $_item->getCount() ?>)
<?php endif; ?>
</li>
<?php endforeach ?>
</ol>
</div>
<script type="text/javascript">
if (navigator.cookieEnabled) {
return true;
} else if (navigator.cookieEnabled === undefined) {
document.cookie = "testcookie";
if (cookie_present("testcookie"))
return true;
} else {
var elem = document.getElementById('shop-by-filters');
elem.parentNode.removeChild(elem);
}
</script>
Can anyone help me with this, or is there a better way of going about it? Please keep in mind that I am still trying to get my head around Magento, so I might need some instructions if the implementation is complicated.
Thank you.
Brendon
I'm not sure if the Google robot will reliably parse your javascript.
You may be better off hiding the layered nav based on the current session with php.
<?php if (Mage::getSingleton('customer/session')): ?>
...your nav code...
<?php endif ?>
First of all, Javascript will do nothing to stop Google from indexing that content.
Why don't you want 'to settle for NoFollowing all the links'? That is exactly what NoFollow is for. You can also tell Google to not pay attention to the qualifiers/query strings in Webmaster Tools.
If for some reason you really wanted to hide that block from Google, edit the template and string compare $_SERVER['HTTP_USER_AGENT'] against Google's very public list of user agents here http://support.google.com/webmasters/bin/answer.py?hl=en&answer=1061943
EDIT -- string compare
<?php if (stripos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false): ?>
<div id="shop-by-filters">
<ol>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if ($_item->getCount() > 0): ?>
<?php echo $_item->getLabel() ?>
<?php else: echo $_item->getLabel() ?>
<?php endif; ?>
<?php if ($this->shouldDisplayProductCount()): ?>
(<?php echo $_item->getCount() ?>)
<?php endif; ?>
</li>
<?php endforeach ?>
</ol>
</div>
<?php endif; ?>
It is a slick subject. We used this code to hide the layered navigation from Google, but we are not sure is it working...
<div id="filters-no-follow"></div>
<?php
function prepare_for_echo($string) {
$no_br = trim(preg_replace('/\s+/', ' ', $string));
$no_slashes = str_replace('\'', '\\\'', $no_br);
return $no_slashes;
}
?>
<script>
function please_enable_cookies() {
var f = document.getElementById('filters-no-follow');
f.innerHTML = '<div class="no-cookies-error">Enable cookies to choose filters.</div>';
}
function please_load_filters() {
var f = document.getElementById('filters-no-follow');
f.innerHTML = '<?php if ( !empty($filtersHtml) || !empty($stateHtml) ): ?>'
+ '\n<div class="block block-layered-nav">'
+ '\n <div class="block-title">'
+ '\n <strong><span><?php echo prepare_for_echo($this->__('Shop By')); ?></span></strong>'
+ '\n </div>'
+ '\n <div class="block-content">'
+ '\n <?php echo prepare_for_echo($this->getStateHtml()); ?>'
+ '\n <?php if ($this->canShowOptions()): ?>'
+ '\n <p class="block-subtitle"><?php echo prepare_for_echo($this->__('Shopping Options')); ?></p>'
+ '\n <dl id="narrow-by-list">'
+ '\n <?php echo prepare_for_echo($filtersHtml); ?>'
+ '\n </dl>'
+ '\n <?php endif; ?>'
+ '\n </div>'
+ '\n</div>'
+ '\n<?php endif; ?>';
}
function are_cookies_enabled()
{
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
{
document.cookie="testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
}
return (cookieEnabled);
}
if(are_cookies_enabled()) {
please_load_filters();
} else {
please_enable_cookies();
}
</script>
I need to add different size chart for different products to my magento store.
Can anybody explain here, How to do this and also give me a solution to do this.
Thanks in advance
formygalaxy
You could do so linking a product attribute (e.g. manufacturer) with static blocks.
See this code:
$sizeGuideIdentifier = trim($_product->getAttributeText('manufacturer'));
$sizeGuideIdentifier = str_replace(' ','-',strtolower($sizeGuideIdentifier)) .'-size-guide';
if($this->getLayout()->createBlock('cms/block')->setBlockId($sizeGuideIdentifier)->toHtml()):
echo $this->getLayout()->createBlock('cms/block')->setBlockId($sizeGuideIdentifier)->toHtml();
else:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-sizeguide')->toHtml();
endif;
It will try to echo out a block called e.g. "nike-sizeguide", if this block doesn't exist it will fall back to the default sizeguide.
yup, this worked perfectly on Magento 1.9CE, although for me Erwin's solution needed to be inserted into "app/design/frontend/.../.../template/catalog/product/view/type/options/configurable.phtml".
Really simple solution and great outcome; we now pop a fancybox sizechart image for each brand (manufacturer) automatically, without coding and our inventory managers don't need to think about it.
Really really great - and much appreciation to Erwin Smit. I hope the good karma has visited you already ;)
<dd <?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
<div class="size-box"><?php
$sizeGuideIdentifier = trim($_product->getAttributeText('manufacturer'));
$sizeGuideIdentifier = str_replace(' ','-',strtolower($sizeGuideIdentifier)) .'-size-guide';
if($this->getLayout()->createBlock('cms/block')->setBlockId($sizeGuideIdentifier)->toHtml()):
echo $this->getLayout()->createBlock('cms/block')->setBlockId($sizeGuideIdentifier)->toHtml();
else:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-sizeguide')->toHtml();
endif;?>
</div>
</dd>
Hello all first sorry for the stupid question.
I am making a small job board with codeigniter, and i ran into a problem.
On the main page it lists the jobs and when i click on them it redirect to the details page with the infos about the job.
My problem is i made a category filter where they can browse the jobs by clicking on a category, and on that page when i click the link for the details its giving me this url: localhost/jobboard/lists/category/lists/details/test-job insted of this localhost/jobboard/lists/details/test-job <-- this is the right one.
<li>
<a href="<?php base_url(); ?>lists/details/<?php echo $res->job_link ?>">
<span><?php echo $res->job_title ?></span>
<p><?php echo $job_type ?> | <?php echo $res->job_location ?> | <?php echo $res->company_name ?></p>
</a>
</li>
and the above code should not show this: *localhost/jobboard/lists/category/lists/details/test-job
Could please soeone give me a hint? because i tried a few things and im totally clueles
Thank you
Darn i got it, i forgot to echo the base url....