I'm new to WordPress, I just converted my HTML to WP Theme, but now I'm facing a problem, I couldn't get to work the linking of pages.
The structure of my theme:
index.php
header.php
sidebar.php
footer.php
services.php <- other page in the site
Here's the sample code from index.php:
<div id="menu">
<ul>
<li><a class="current" href="#">Home</a></li>
<li>Services</li>
<li>Free Quote</li>
<li>Customers</li>
<li>About Us</li>
<li>Contact us</li>
</ul>
</div>
But whenever I try to go to services, it's giving internal server error. I don't know why it's happening.
There are two ways in wordpress for linking Pages
For Content Based pages only:
You need to create a page from wp-admin(Admin panel) and can specify the slug of the page
E.g:
<li>Services</li>
^This is called Slug
This page will always run from page.php.
For HTML Changes Pages:
You need to create a page from wp-admin(Admin panel) and create a file containing
page-slug.php, here slug will change according to the name of page.E.g:
Services page will become page-services.php, in this you can insert your own html.
This will run from page-services rather than page.php
Choose as per your requirement.
Try using:
<a href="<?php echo bloginfo("template_url")?>/services.php">
I think in this case you are just not echoing out the value of that function. Also, however you might want this instead:
<a href="<?php echo home_url() ?>/services">
The template_url goes to your theme's folder, not to your website's homepage. I assume the latter is what you're really going for.
try <php echo site_url()."/sevices.php"; ?>
Related
I have an archive events page that links to a single page that lists all previous events created in the past and can only be visited via the archive events page.
My question is, how can I highlight the archive events page url link when viewing this single page?
For example the below snippet targets a hard-coded nav link to highlight the events link when viewing the other page, however my menu is not hard-coded:
<nav class="main-navigation">
<ul>
<li>...</li>
<li>...</li>
<li>
<?php if(get_post_type() == 'event' OR is_page('past-events')) echo 'class="current-menu-item"';?>>
events
</li>
<li>...</li>
</ul>
</nav>
The tutorial I am following does not give the alternative coded way of targeting this similarly in the functions.php page, for a dynamic menu that is created via the wordpress dashboard menu.
I have tried searching for examples, but I havent found anything that has helped so far and in need of some outside help.
How can I do this?
I can see something wrong. you haven't put the php code in right place. corrected code is this. try this and let me know if it works
<nav class="main-navigation">
<ul>
<li>...</li>
<li>...</li>
<li <?php if(get_post_type() == 'event') echo 'class="current-menu-item"';?>>
</li>
<li>...</li>
</ul>
</nav>
Ok, I think I have found a solution -- being a novice -- has worked!
Hopefully someone can point out any changes/improvements I could make, but here it is:
To highlight a menu link for a different page than the one that you are on/viewing, for example in my scenario: I have an archive events page and within that page I have a link that takes you to a single page that lists all past previous events, but that has no link in the main navigation to it.
function nav_class($classes) {
// Remove "current-menu-item" class
$classes = array_diff($classes, array('current-menu-item'));
// If this is the "past-events" page, highlight the event menu item
if (in_array('menu-item-36', $classes) && is_page('past-events')) {
$classes[] = "current-menu-item";
}
return $classes;
}
add_filter('nav_menu_css_class', 'nav_class', 10, 2);
I hope this helps someone else out.
I have a footer navigation inside an unordered list.
How do I link these navigation links to the pages in my WordPress site? I have tried the following code but it doesn't work.
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>About Me</li>
</ul>
The best way is to use
Pagename
This way the link stays consistent, even if the slug changes - if you want to echo home_url() or get_permalink( get_option( 'page_for_posts' ) ) for other content
I am using Magento 1.9.
My top menu contains categories as menu items.
I have managed to open static CMS page when clicked on menu item (i.e. category) by adding custom URL rewrite rule from admin panel.
How I can add menu item with external link to it so that page will get redirected to other website when clicked on menu item.
My Magento website is going to be under subdoamin and external link will be of main doamin.
Magento site will be hosted on http://domain.xyz.dom/ and I need to redirect to http://www.xyz.dom/abc when clicked on menu item.
The way you added cms page in "URL Rewrite Management" you can add external url too.
Create a category, in my case category ID is 3
Add a new URL Rewrite from URL rewrite management
Enter ID Path: category/3
Enter Request Path: catalog/category/view/id/3
Enter your external url in "Target Path"
There can be two ways of redirecting the way you are trying.
From Cateagory Url rewrite management which i guess you have tried so far.
Another way is little messy but it will work you just have to add a static link on the template file.
I mean go to the file
app/design/frontend/your_package/your_theme/template/page/html/topmenu.phtml
you will see some code like this
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
I have replaced this to add a home page link on the menu see below.
<?php $_menu = $this->getHtml('level-top') ?>
<?php $baseUrl = Mage::getBaseUrl();?>
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>
<?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<li class="level0 nav-1 <?php if($baseUrl==$currentUrl){echo 'active';}?>">Home</li>
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
In this way you can add your link.
Hope this helps. Happy Coding!!
I've in header.php list items containing:
home
about us
support
contact us
I need to link them with php files in my theme in wordpress:
index.php
about-us.php
contact-us.php
support.php
I tried for home this code:
<li>Home</li>
and worked with home page only.. so what about the other files
I need something similar to
about us
because any page have included different header, footer and other
Hi Can you try this code
<li>about us</li>
I have created 2 CMS pages in magento 1.7.2
Lets say the cms page "About Us" which is the URL
http://localhost/magento/index.php/about-company/?___store=default
and the page "Customer Service" which is the URL http://localhost/magento/index.php/customer-service/?___store=default
In my HEADER.PHTML the line getChildHtml('topMenu') ?> shows the topmenu.
the problem is that the 'topMenu' contains only the categories created by Catalog->Manage Categories
What is the appropriate way to include the 2 cms pages ("About Us" and "Customer Service")
in the 'topMenu' ?
Thank you for your help !
Create a static block for cms pages from admin and write the below format code
<ul>
<li>About Company</li>
<li>Customer Service</li>
</ul>
Call this block in topmenu.phtml (/template/page/html/topmenu.phtml) page
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('cms_pages')->toHtml();?>
Add following code under your /template/page/html/topmenu.phtml
<li title="<?php echo $this->__('About Company') ?>"><?php echo $this->__('About Company') ?></li>