I have a list that at the moment that looks like this:
div.product ul.custom-attributes li.pa_attribute {
list-style-type: none; margin-left: -18px; padding-left: 25px;
}
div.product ul.custom-attributes li.pa_attribute:first-child {
background: url("/wp-content/uploads/2014/09/cf.png") no-repeat scroll left center rgba(0, 0, 0, 0)
}
div.product ul.custom-attributes li.pa_attribute:first-child +li {
background: url("/wp-content/uploads/2014/09/df.png") no-repeat scroll left center rgba(0, 0, 0, 0)
}
div.product ul.custom-attributes li.pa_attribute:first-child +li +li {
background: url("/wp-content/uploads/2014/09/ft.png") no-repeat scroll left center rgba(0, 0, 0, 0)
}
But the order of the list will change so I need to apply the CSS according to a rule. Is it possible to do this using PHP? The URLs are out put like this with an âattributeâ code attached, if this helps.
Yes, the output from your echo() statement forms part of the html content thatâs delivered to the browser, so as long as the conditional is run in the header of the page where you would normally add CSS rules, it shouldnât be an issue.
Another option would be to use the include statement and hold the CSS in a separate file
if ($_GET['filter_attribute'] == '552' ) {
include "custom_css.css";
} else {
include "usual_css.css";
}
Looking at your original link, you donât seem to have a page name on there, just a directory which (presumably) then serves up the default page on opening that directory, perhaps via some redirect mechanism. If thatâs true, I donât think youâll make it work because the redirect will strip the parameter. Easy way to tell is
<?php
echo $_GET['filter_attribute'];
?>
There may be some way to configure the server to keep parameters for this - Iâm not up to speed on how these things work in the real world. Can you add the php page name to your link and try again, just to see if that helps?
Trying that bit of code didnât return anything, but there are a number of these filter attributes links on the page, would it struggle to return a value?
The permalinks within Wordpress are set to friendly links. The ânon-friendlyâ links look like thus: