Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.57 KB | None | 0 0
  1. QUICK NOTE - Just to clear things up:
  2. The website's Logo DIV is loaded BEFORE the featured content comes into play, as part of Thematic's "header.php" file. This means I have to find a way to load CSS variables when the randomized featured content is being loaded.
  3.  
  4. If there's some way to selectively load variables from a PHP (as opposed to loading an entire PHP with <?php include "file.php"; ?>), I'd love to know. I'm totally without knowledge when it comes to PHP, I just tinker and search for answers as needed.
  5.  
  6.  
  7. original text below
  8. -------------------
  9.  
  10. HERE'S THE DEAL.
  11.  
  12. I'm working over a small website for Corbin (using Wordpress, the "Thematic" theme, and the "Thematic Feature Site" child theme). The way the site is built at the moment, a different featured item is randomly displayed upon each refresh. Each featured item has its own CSS styles, making each item stand out on its own rights.
  13.  
  14. I'm trying to make use of PHP as CSS, in order to have the website's logo "change color" to match the featured material. I'm using a transparent PNG as the _background image_ of a DIV tag. The PNG acts as a mask, allowing me to set the color of the logo by changing the _background color_ of the Logo DIV tag.
  15.  
  16.  
  17. The path I'm currently taking is as follows:
  18.  
  19.  
  20. The featured content starts with "rand.php", which contains this code:
  21. <?php
  22. $rand = mt_rand(1, 4);
  23. ?>
  24. This controls the random selection for the featured content.
  25.  
  26. The featured content is called by "pageleader.php" with the following code:
  27. <?php
  28. include "rand.php";
  29. include "includes/feature-front-$rand.php";
  30. /*
  31. Highlight your most important projects with a series of files (2 to start with) named feature-front-###.php.
  32. Where ### is a number. Then, these files are randomly included on the front page. It's pretty simple stuff.
  33.  
  34. The important bit is the mt_rand(1,2). Right now it's randomly including 1 of 2 files.
  35. If you had 15 files you'd need to have mt_rand(1,15) in there.
  36. */
  37. ?>
  38.  
  39. The code featured in "rand.php" was originally already integrated with "pageleader.php" - I had to separate them into their own PHP files, as problems were always encountered when the PHP CSS (below) would try to load "includes/feature-front-$rand.php" as well. This would result in the PHP CSS breaking, as all four "feature-front-###.php" files feature this section of code:
  40. <?php echo dirname( get_bloginfo('stylesheet_url') ) ?>
  41.  
  42.  
  43. Following this is my PHP CSS file, which only has this bit of PHP code:
  44. <?php
  45. include "rand.php";
  46. include "includes/feature-header-$rand.php";
  47. ?>
  48.  
  49. The rest is CSS code, save for this PHP call in the Logo DIV:
  50. background-color: <?php echo $headercolor; ?>;
  51.  
  52.  
  53. And finally, in relation to the above code for the PHP CSS file, "feature-header-$rand.php" (feature-header-###.php, operating the same way as feature-front-###.php) only contains the code necessary to set the background color of the Logo DIV:
  54. <?php
  55. $headercolor = '#1c3f55';
  56. ?>
  57.  
  58. I originally had four variations of this code inside their respective "feature-front-###.php" files, but as outlined earlier, all four "feature-front-###.php" files feature a line of code which subsequently breaks the PHP CSS file.
  59.  
  60.  
  61.  
  62. The website DOES load the featured items, and the background color for the Logo DIV. But PHP insists on calculating SEPARATE random numbers for both "feature-front-###.php" and "feature-header-###.php", rather than using a single calculation for both, resulting in undesired combinations of the two files. The issue is merely cosmetic, and ultimately doesn't hinder how the website performs. It's just an outright pain in the ass.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement