I'm using the following tutorial to create a one page website:
http://www.insitedesignlab.com/how-to-make-a-single-page-website/
Is it possible to change the color of the menu item depending on what anchor is selected?
This is how I've setup the menu
<?php $current = $post->ID; $counter = 1; $mypages = get_pages(array('sort_column' => 'menu_order'));
foreach( $mypages as $page ) { ?>
<?php if ($current == $page->ID) { ?>
<li><a style="color:white!IMPORTANT;" id="menu<?php echo $counter; ?>" href="#section<?php echo $counter; ?>"><?php echo $page->post_title; ?></a></li>
<?php } else { ?>
<li><a id="menu<?php echo $counter; ?>" href="#section<?php echo $counter; ?>"><?php echo $page->post_title; ?></a></li>
<?php } ?>
<?php $counter++; } ?>
So each menu iterates by 1 each time it loops.
You can try Jquery Tabs... Maybe its easier
Sure, I think the right approach here is to bind the tabs, I mean not depending in the anchor, so everytime a tab is clicked it will change,so first you have to add a class to all tabs like so:
<li><a style="color:white!IMPORTANT;" id="menu<?php echo $counter; ?>" class="tab" href="#section<?php echo $counter; ?>"><?php echo $page->post_title; ?></a></li>
after that you just need to bind the tab elements to the click function to fire the event every time a tab is selected:
$(".tab").click(function(e){
$(".tab").css("color", ""); //Remove the color from all tabs
$(this).css("color", "white!IMPORTANT"); //Apply the "highlight" color to the selected
});
this way we remove the color from all "tab" elements, and then we apply the color to the selected tab.
It would be better if you use a css class for the link that you want to be highlighted.
CSS:
.linkactive{
color:pink;
font-weight:bold;
}
jQuery:
$("#nav a").click(){
$(".linkactive").removeClass("linkactive");
$(this).addClass("linkactive");
});
Please remember to add the class "linkactive" to your home or starting tab.
Related
I want to make one image active each when it is selected, but right now all items are active
<?php foreach($project_images as $image) {?>
<?php
if($image['project_image_name'] != '') {
$images = '<img src="'.base_url().'public/uploads/project_images/'.$image['project_category'].'/'.$image['project_id'].'/'.$image['project_image_name'].'" >';
} else {
$images = '<img src="'.base_url().'public/uploads/project_images/default/default-project-image.jpg'.'" ';
}
?>
<div class="carousel-item active">
<?php echo $images; ?>
</div>
<?php }?>
This sounds like a job for JavaScript, not PHP.
I'm assuming PHP doesn't know if the image is active or not, it just displays the image.
I'm assuming you want the image to be active when it's clicked. That's JavaScript.
Step 1: Don't make anything active.
Remove 'active' from the div.
<div class="carousel-item">
<?php echo $images; ?>
</div>
Step 2: Give each div a unique identifier so JavaScript knows what element you're referring to.
<?php
$id = 0;
foreach($project_images as $image) {
$id++;
?>
<?php
// .. code is the same
?>
<div id="carousel_<?php echo $id ?>" class="carousel-item">
<?php echo $images; ?>
</div>
<?php }?>
That should give each div a unique id.
Step 3: Create a JavaScript function that will toggle the 'active' class of the selected item.
Ex:
function ToggleClass(elemID){
// Get selected element
selElement = document.getElementById(elemID);
//Use selElement to change class. Code goes here
}
Step 4: Add the JavaScript function to the div.
Note the quotes -- use the double and singles as needed.
Ex:
<div id="carousel_<?php echo $id ?>" class="carousel-item active" onclick="ToggleClass('carousel_<?php echo $id ?>')">
<?php echo $images; ?>
</div>
I'm using Luxury theme in Magento. I'm trying to display current category name in the catalog/category/view.phtml file.
What I have done so far:
<div class="custom">
<?php if($crumbs && is_array($crumbs)): ?>
<div class="container">
<div class="col-md-12">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>" <?php if(Mage::getStoreConfig('mgs_theme/general/snippets') == 1): ?> itemscope itemtype="http://data-vocabulary.org/Breadcrumb" <?php endif ?>>
<?php if($_crumbInfo['link']): ?>
<a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->escapeHtml($_crumbInfo['title']) ?>" <?php if(Mage::getStoreConfig('mgs_theme/general/snippets') == 1): ?> itemprop="url" <?php endif ?>><span <?php if(Mage::getStoreConfig('mgs_theme/general/snippets') == 1): ?> itemprop="title" <?php endif ?>><?php echo $this->escapeHtml($_crumbInfo['label']) ?></span></a>
<?php else: ?>
<strong><span <?php if(Mage::getStoreConfig('mgs_theme/general/snippets') == 1): ?> itemprop="title" <?php endif ?>><?php echo $this->escapeHtml($_crumbInfo['label']) ?></span></strong>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>| </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif ?>
</div>
I have taken this code from page/html/breadcrumbs.phtml.
I am totally new to Magento/PHP. It doesn't show any error but it's not displaying the name of the category, while it's visible in breadcrumbs header. What I am doing wrong here?
If you want to show category name on category page. You can achieve this by 2 ways.
<?php echo $this->getCurrentCategory()->getName(); ?>
Or
<?php echo Mage::registry('current_category')->getName() ?>
On our site (magento 1.9) we wanted to show the first parent category of the current product on our product pages and provide a link to it. I achieved this as follows - you should be able to reverse engineer my code to your own ends.
At first I did it by adding the following code directly to the catalog/product/view.phtml but have since migrated it into a custom helper in my own module.
Here's the code, see if it works for you.
//get an array of the IDs of every category to which the product belongs.
$categoryIds = $_product->getCategoryIds();
//set CatID to the second element of the array since the first element
//is the base category of which all others are children.
$_catID = $categoryIds[1];
//load the correct model
$_category = Mage::getModel('catalog/category')->load($_catID);
//get the level of the current category
$level = $_category->getLevel();
//This if statement prevents the function from trying to run on products
//which are not assigned to any category.
if($_category->getName()){
// we want the second level category, since the first is the base category.
// ie if we call the default category 'base' and the product is in category
//base->foo->bar->baz we want to return the link to foo.
// while current category is deeper than 2 we ask it for it's parent
//category until we reach the one we want
while ($level > 2){
$parent = $_category->getParentId();
$_category =Mage::getModel('catalog/category')->load($parent);
$level = $_category->getLevel();
}
//Now we can build the string and echo it out to the page
$caturl = $_category->getUrl_key();
$_linkstring = 'http://www.yourwebsite.com/' . $caturl . '.html';
echo 'in category:';
echo '<a href="' . $_linkstring . '" title="'. $_category->getName() .'">';
echo ' '. $_category->getName();
echo '</a>';
}
Get the category name, image, description from category id in magento
$category = Mage::getModel('catalog/category')->load(category_id);
echo $category->getName();
echo $category->getImageUrl();
echo $category->getDescription();
Please put the category id in the load function
I have this PHP code that works excellent in displaying arrows to previous/next pages of WordPress child pages:
<?php // Button Code for Prev and Next Page
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(
array('post_type' => 'page'));
$portfolio = get_page_by_title('Services');
$args = array (
'child_of' => $portfolio->ID,
'sort_order' => 'asc',
'post_type' => 'page'
);
$portfolio_children = get_pages( $args );
$pages = array();
foreach ($portfolio_children as $page) {
$pages[] += $page->ID;
}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="previousarrow">
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">
<img src="<?php bloginfo('url');?>/wp-content/uploads/2016/06/previousbutton.png">
</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="nextarrow">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">
<img src="<?php bloginfo('url');?>/wp-content/uploads/2016/06/nextbutton.png">
</a>
</div>
<?php } ?>
</div>
Problem is that on the first and last pages, I can't get it to show the previous/next button to go to the 'last or first' page of the child pages.
Example
A (parent)
1 (child page 1)
2 (child page 2)
3 (child page 3)
I want the previous option on page 1 to go to page 3 and vice versa but I can't figure that out. Any help is appreciated.
The buttons are not appearing because of the php if parameters, which eliminates the previous arrow on page 1 and next arrow on page 3 because it recognizes them as empty. One way around this would be to remove the if clauses and use if statements to define your prevID and nextID variables, or you can simply add else statements after each if statement defines the previous/next buttons to be shown. However, both of these solutions are temporary, as you would require the number of pages in order to implement them, which is subject to change. Instead, use this code to ensure this feature will stay intact even if you add additional pages:
<?php if (empty($prevID)) { $firstpage = $pages[$current]; }
if (empty($nextID)) {$lastpage = $pages[$current]; }
This will define the value of the first and last pages, and can simply be inserted after you define prevID and nextID. Now simply add php else statements like so:
</div> <?php }
else { ?>
<div class="previousarrow>
<a href="<?php echo get_permalink($lastpage); ?>"
title="<?php echo get_the_title($lastpage); ?>">
<img src="<?php bloginfo('url');?>
/wp-content/uploads/2016/06/previousbutton.png"></a></div>
<?php }
This block of code would be inserted after your first div class, as the previous arrow should navigate to the last page when no previous page exists. Do the exact same after the second div class, replacing the lastpage variable with the firstpage one we created. Hope this helps!
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()
How do you hide specific content if $page = name
For example:
<?php
if ($page=='special'){
echo "<div>hello</div>";
}
?>
The above example will show the div if the $page = special. How do I do the opposite of this, hide a specific div if the $page = something?
Edit:
To be more specific I would like to hide my main navigation when on the $clients page.
Do I wrap the <nav> with PHP or is it possible to hide a specific div if I give it a name, for example. <nav id="clients"> the PHP would be: if $clients then hide the id named clients.
I should also mention that the content in question has <?php echo $url; ?> and the likes contained within it.
This is the exact content I would like to hide on $clients pages.
<nav>
<ul>
<li><a <?php if ($page=="work") echo "class=\"current\"" ?> href="<?php echo $url; ?>" title="Work">Work</a></li>
<li><a <?php if ($page=="profile") echo "class=\"current\"" ?> href="<?php echo $url; ?>profile/" title="Profile">Profile</a></li>
<li><a <?php if ($page=="approach") echo "class=\"current\"" ?> href="<?php echo $url; ?>approach/" title="Approach">Approach</a></li>
<li><a <?php if ($page=="contact") echo "class=\"current\"" ?> href="<?php echo $url; ?>contact/" title="Contact">Contact</a></li>
</ul>
</nav>
hide a specific div if the $page = something?
if ($page !='special'){
echo "<div>hello</div>";
}
You just echo it if $page is different from something.
If you want, you can also echo it anyway but as 'hidden' if that's what you're trying to achieve.
if ($page =='special'){
echo "<div>hello</div>";
} else {
echo "<div style='display:hidden;'>hello</div>";
}
This way, the div will be in the DOM anyway and you can show it later on without reloading the page using JavaScript.
If you want it on every other page that is not special
<?php
if ($page!='special'){
echo "<div>hello</div>";
}
?>