I have some php which works on my site to style a link. However, when I try to use the same code to style other links in a different way, it breaks my site.
For example I have:
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.events-dashboard1 {background-color: green;}
</style>';
}
This works but when I try to duplicate like so:
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.post-job1.post-event1 {background-color: #e5f25c; color: white
!important;}
</style>';
}
The site breaks. I've investigate and found that using multiple classes like that doesn't work. But if I repost the same php code just with 1 class, it breaks. Tried altering the format - nothing.
Html:
<div id="adminmenuwrap">
<ul id="adminmenu">
<li class="wp-first-item wp-has-submenu wp-has-current-submenu wp-
menu-open menu-top menu-top-first menu-icon-dashboard menu-top.
first" id="menu-dashboard">
<a href='index.php' class="wp-first-item
wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-
top-first menu-icon-dashboard menu-top-first">
<div class="wp-menu-
arrow"><div></div>
</div><div class='wp-menu-image dashicons-before
dashicons-dashboard'><br /></div>
<div class='wp-menu-
name'>Dashboard</div>
</a>
<ul class='wp-submenu wp-submenu-wrap'>
<li class='wp-submenu-head' aria-
hidden='true'>Dashboard</li>
<li class="wp-first-item current">.
<a href='index.php' class="wp-first-item current"
aria- current="page">Home</a></li>
<li><a href='update-core.php'>Updates
<span class='update-plugins count-37'><span class='update.
count'>37</span></span></a></li>
<li class="jobs-dashboard1"><a
href='https://adsler.co.uk/jobs-dashboard/' class="jobs.
dashboard1">Jobs</a></li>
<li class="post-job1"><a
href='https://adsler.co.uk/post-a-job/' class="post-job1">Post A
Job</a></li>
<li class="events-dashboard1"><a
href='https://adsler.co.uk/your-events-dashboard/' class="events.
dashboard1">Events</a></li>
<li class="post-event1"><a
href='https://adsler.co.uk/post-an-event/' class="post-event1">Post
An Event</a></li>
</ul>
</li>
So now I have four links, two of which I can't style, the other two are styles by above code and the following code. One for each:
function custom_admin_css() { echo ' <style> .jobs-
dashboard1 { background-color: green; } </style>'; }
add_action('admin_head', 'custom_admin_css');
Just put all of your styles under the same tag. It appears you are trying to use the same function twice, which you cannot do.
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.events-dashboard1 {background-color: green;}
.post-job1, .post-event1 {background-color: #e5f25c; color: white
!important;}
/* Any other CSS you have put here */
</style>';
}
Ultimately, what you should do, is create a CSS file. Put your CSS in it. Then enqueue it. Like this.
admin-styles.css
.events-dashboard1 {background-color: green;}
.post-job1, .post-event1 {background-color: #e5f25c; color: white
!important;}
/* the rest of your CSS */
enqueue the file
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
wp_enqueue_style('admin-css', '/path/to/file/admin-styles.css');
}
Related
I want to put my menu in a separate PHP file so when I need to edit it, I only have to edit it once. The problem starts when I want to highlight the active page. Can someone help me to fix it?
<?php $currentPage = basename($_SERVER['SCRIPT_FILENAME']); ?>
Toggle navigation
<li></span> Home</li>
<li></span> About us</li>
<li class="dropdown">
<span class="glyphicon glyphicon-calendar"></span> Services <span class="caret"></span>
<ul class="dropdown-menu">
<li></span> Drivers services</li>
<li></span> Shop services</li>
</ul>
</li>
<li></span> On-line Application</li>
<li></span> Contact us</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="clearfix"> </div>
</div><!-- navbar -->
I find the solution to my question adding this css in styles file:
/* The here ID identifies the current page and applies a white color to the text and a black background as a visual indicator. */
a#here {
background-color: #000 !important;
color: #fff !important;
}
Plus call the menu in each page with following code:
<div> <?php
$file ='includes/menu.php';
if (file_exists($file) && is_readable($file)) {
include($file);
} else {
throw new Exception("$file can't be found");
}
include('includes/menu.php');?>
</div>
A quick and dirty method to achieving this is in each file put the following:
<?php
include("header.php"); // Insert location of header file here
?>
and in your header.php file after creating your head block insert this
<?php $active= substr(basename($_SERVER['SCRIPT_FILENAME']),0, -4); ?> // Page Name
<body <?php echo "class='$active'";?>> // This sets the bodies class to be the page name.
finally in style.css use the following code to set the highlighted feature
// This is an example for my CSS. Insert your own css selector
// In my css i have this which adds a small orange bar to the bottom of the navigation option. I set the opacity to 0 to not display it.
.header nav ul li a:before
{
height: 5px;
background: #ea5c18;
opacity: 0;
}
// Then i set .PageName (the bodies class name) and set that specific nav element to have an opacity of 1.
.PageName .header nav ul li:first-child a:before
{
opacity:1;
}
I am trying to add '+' Symball in front of category navigation on left side
I am using magento 1.9.x
This code i fount in category-navigation.phtml
I want to know how <?php echo $_menu ?> this comes from?
<div class="block vertical-menu">
<div class="title-block" style="margin-bottom:0px;"><h4><?php echo $this->__($title) ?></h4></div>
<div class="block-content">
<ul id="content-navigation">
<?php echo $_menu ?>
</ul>
</div>
</div>
My suggestion would be to do it in CSS. You can use Ionicons or something similar.
The $_menu html is generated inside the block class, rather than using a phtml file. So, you could extend that block and customize it, but this can also be achieved using CSS without having to worry about extending the block.
An example would be the following:
Example HTML
<nav id="nav">
<ol>
<li>Plus Sign</li>
<li class="active">Minus Sign</li>
</ol>
</nav>
Example CSS - This requires Ionicons
ol {
list-style: none;
}
#nav li::before {
font-family: Ionicons;
content: '\f489';
padding-right: 10px;
}
#nav li.active::before {
content: '\f209';
}
JS Fiddle - A working sample
https://jsfiddle.net/adpro/5xbw80b1/
I'm creating an custom template for wordpress, and I got problem with menu. I want to create menu in the sidebar.
I got static menu like this:
<ul class="purp_bullet">
<li><a href="#sub-1">A/a>
<ul id="sub-1">
<li>B</li>
<li>B</li>
<li>B</li>
<li>B</li>
<li>B</li>
</ul>
</li>
<li><a href="#sub-2">C/a>
<ul id="sub-2>
<li>D</li>
<li>D</li>
<li>D</li>
<li>D</li>
<li>D</li>
</ul></li>
<li>E</li>
<li>F</li>
<li>G</li>
</ul>
With CSS like this:
ul.purp_bullet {
list-style-image: url('img/list_bullet.png');
padding-left: 17px;
text-decoration: none;
}
ul.purp_bullet li a {
color: #003366;
text-decoration: none;
}
ul.purp_bullet li a:hover {
color: red;
text-decoration: none;
}
ul.purp_bullet li a:active {
color: red;
text-decoration: bold;
}
I want it to be fully dynamic, just like wordpress menus, when I go into menu section in admin panel and create my own menu from pages that i created, then drag "my custom menu" onto widgets panel (sidebar) so it shows up. Note that this isn't my main menu (I already got the menu in header).
Also there is one more thing I need to do.
I got pages like employers and when I'm on some employer page the menu must be expanded( or rolled down, sorry for my bad english :x), but when i'm on other page it must be rolled up.
Screens:
When I'm on some employer page
When I'm on other pages like contact etc
Do i need create new menu in functions and then hook it like my main menu?
Can anyone help me how to do it?
I've never used the php include function but I recently read some good articles which encourage ti.
I'm going to use it mainly for menus and footers, but here's my question:
How can I attach a HTML class to a menu element.
e.g.
menu.php
<nav>
<ul>
<li>home</li>
<li>blog</li>
<li>about</li>
<li>contact</li>
</ul>
</nav>
index.html
<?php include 'menu.php'; ?>
In this case how do I set a class to any of these menu elemnts without using different menu.php files?
Long story short I need it so I can apply certain styles to a single element in the list, and each html file will match the specific menu voice
E. G. index.html will have the "home" anchor styled differently than other three elements.
Thanks in advance.
As per these examples
You can make use of option #2
CSS
#nav {
width:150px;
list-style:none;
}
#nav a {
color:black;
text-decoration:none;
}
#nav a:active, #nav a:focus, #nav a:hover {
color:red;
}
#home #homenav, #about #aboutnav, #contact #contactnav {
color:red;
}
#home #homenav:hover, #about #aboutnav:hover, #contact #contactnav:hover {
color:blue; /* add :active and :focus styles here also */
}
HTML
<body id="home"> <!-- the body needs a unique id -->
<ul id="nav"> <!-- each anchor needs a unique id -->
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</body>
Give your elements ids and set the class in the including file.
The links on the images are being hidden or covered and I cannot figure out why. The first <a href.. below is an example of this.. Live version can be found here.. Basically any of the product images should be clickable..
<div class="image-wrap">
<a href="http://fundraisingfountain.pixelworklab.com/product/bull-dog/" title="Bull Dog">
<img width="150" height="150" src="http://fundraisingfountain.pixelworklab.com/wp-content/uploads/2013/06/Pillow-Pets-Bulldog-2-150x150.png" class="attachment-shop_catalog wp-post-image" alt="Pillow Pets - Bulldog (2)">
</a>
<ul class="product-details">
<li class="details">
<a class="button details" href="http://fundraisingfountain.pixelworklab.com/product/bull-dog/" title="Bull Dog">View Details</a>
</li>
<li class="price-wrap">
<span class="price"><strong><span class="amount">$25</span></strong></span>
</li>
<li class="cart">
Add to cart
</li>
</ul>
</div>
It works fine on my machine.
You'll have to check your CSS and make sure that there are no div tags that are layered on top of it (or have a higher z-index than it).
That is because you have set ul height:100% that is why it overlaps the image.
Change the height for the ul to something smaller and it will work fine
woocommerce.css Line # 634
ul.products li.product .product-details{
height:25px;
}
btw if you give a
border="0"
to your image links there wil be no grey (or any other color) border around it
Here's what you need to fix
ul.products li.product .product-details {
height: auto;
top: 108%;
}
ul.products li.product .product-details li {
vertical-align: middle;
}