I am trying to set a WWW_ROOT in order to reuse HTML code in different pages. This is an example of users.php using a header, where the CSS files are not found - 404 (Not Found) and I got Notice: Undefined variable: project_end in /Applications/XAMPP/xamppfiles/htdocs/lpweb/assets/php/initialize.php on line 11
Folder structure
>localhost
>lpweb
>index.php
>pages
>users.php
>assets
>php
>initialize.php
>header.php
>css
>bootstrap.min.css
initialize.php
<?php
define("PHP_PATH", dirname(__FILE__));
define("ASSETS_PATH", dirname(PHP_PATH));
$public_end = strpos($_SERVER['SCRIPT_NAME'], '/lpweb') + 7;
$doc_root = substr($_SERVER['SCRIPT_NAME'], 0, $project_end); //line 11
define("WWW_ROOT", $doc_root);
?>
header.php
<link rel="stylesheet" media="all" href="<?php echo WWW_ROOT . 'assets/css/bootstrap.min.css'; ?>"> />
users.php
<?php require_once('../assets/php/initialize.php'); ?>
<?php include(PHP_PATH . '/header.php'); ?>
You are mixing $public_end and $project_end
Also after reviewing your code from GitHub I believe this will work for you.
define("WWW_ROOT",$_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'].rtrim($_SERVER['REQUEST_URI'],'/'));
Alternatively, you can use the relative path to refer to CSS files which will make your life easy
<link rel="stylesheet" media="all" href="assets/css/bootstrap.min.css" />
Related
So I want to add placeholder text to the Username and Password fields on the standard wp-login.php page - I don't want to edit the actual wp-login.php page because every time WordPress is updated my amends will just be wiped.
So! In functions.php I've added a simple function to add a .js file (and some css files but I don't think that's important for this) to the wp-login.php page where I have this code - here is my function in functions.php
function my_custom_login() {
echo '<link rel="stylesheet" type="text/css" href="/shared-assets/css/main-screen-styles.css" />';
echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/css/campsite-finder-screen-styles.css" />';
echo '<script type="text/javascript" href="/shared-assets/js/test.js">
</script>';
}
add_action('login_head', 'my_custom_login');
And here is my js file
jQuery(document).ready(function(){
jQuery('#user_login').attr('placeholder', 'Name');
jQuery('#user_email').attr('placeholder', 'Email');
jQuery('#user_pass').attr('placeholder', 'Password');
});
And this is where I get stuck .. in my mind that should work, I've checked the IDs and they all seem to line up but I'm clearly doing something wrong, you can see the page here http://www.camp-site-finder.com/wp-login.php
If you view the source you can see the link to my .js file and I'm referencing jQuery so errmm, have I done something stupid along the way or is there a better way of doing this?
If anyone can point me in the right direction on this one I'd be very grateful
N
you didn't include .JS file in <script src="something.js"> . you have included it in <link rel=stylesheet > tag that's the problem i have found in your page
I've an application build in Yii2 framework, and I've develop the application in backend side, but know I want to copy them become a module.
This my application dir
backend
--modules
--pstk
--controllers
--ValidationController.php
--DefaultController.php
--InterviewController.php
--StudentController.php
--SiteController.php
--UsersController.php
--models
--Validation.php
--Interview.php
--Student.php
--Users.php
--views
--validation
--_form.php
--view.php
--index.php
--update.php
--create.php
--interview
--student
--users
--Module.php
--web
--css
--manual_general.css
--js
--upload_header.js
--style
For example I've successfully run view.php from the module in browser, but the module can't access the .css and .js from backend/web/.
So the view displayed, but it's view mashed-up and all button didn't do any action when clicked.
Anyone know why the module didn't access the manual_general.css and upload_header.js from backend/web/? and how I can solve this problem?
Any help, will be appreciated. Thanks :)
EDITED:
This is the code in mi view.php to connect to .js and .css
<link rel="stylesheet" type="text/css" href="../../../../web/css/manual_general.css">
<script type="text/javascript" src="../../../../web/js/upload_header.js"></script>
Try using yii\helpers\Url::to, like:
<link rel="stylesheet" type="text/css" href="<?= Url::to('#web/css/manual_general.css') ?>">
<script type="text/javascript" src="<?= Url::to('#web/js/upload_header.js') ?>"></script>
Alternatively, in view.php you may do (assuming $this is your View instance):
<?php $this->registerCssFile('#web/css/manual_general.css'); ?>
<?php $this->registerJsFile('#web/js/upload_header.js'); ?>
I have a small problem with importing links. Once I started using pretty URL directories stops working. What can I do ?
Screenshots:
Before
After
Make your css and js links dynamic.
For example:
<?php define( 'SCRIPT_ROOT', 'http://'.$_SERVER['HTTP_HOST'].'/' );?>
<link href="<?php echo SCRIPT_ROOT ?>site/static/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" media="all">
After this doesnt matter your directory structure.
hello genius programmers. can you help me to combine this all css files into one file
<link type='text/css' rel='stylesheet' href='css/header.css' />
<link type='text/css' rel='stylesheet' href='css/body.css' />
<link type='text/css' rel='stylesheet' href='css/sidebar.css' />
<link type='text/css' rel='stylesheet' href='css/footer.css' />
i want to combine all css file into one.
ex:
<link type='text/css' rel='stylesheet' href='css/all.css' />
You can do that easily in PHP. And a very formal method of doing and including is that. Most of them are following up this method alone.
Create a PHP file called styling.php and you can include all the css files over to that PHP file and then you can include it into your file.
styling.php
Under this file you can have the following code.
<link type='text/css' rel='stylesheet' href='css/header.css' />
<link type='text/css' rel='stylesheet' href='css/body.css' />
<link type='text/css' rel='stylesheet' href='css/sidebar.css' />
<link type='text/css' rel='stylesheet' href='css/footer.css' />
And in the PHP file you can call like this with the help of include()
include() - The include statement includes and evaluates the specified file.
Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing. The include construct will emit a warning if it cannot find a file; this is different behavior from require, which will emit a fatal error.
If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.
include() will only produce a warning (E_WARNING) and the script will continue
<html>
<head>
<?php include('styling.php'); ?>
</head>
<body>
</body>
</html>
And when you view the pagesource it will display all the links separately.
Some More for clear understanding of include()
Solution One:
vars.php
<?php
$color = 'green';
$fruit = 'apple';
?>
test.php
<?php
echo "A $color $fruit"; // A
include 'vars.php';
echo "A $color $fruit"; // A green apple
?>
Solution Two
Assume we have a standard footer file called "footer.php", that looks like this:
<?php
echo "<p>Copyright © 1999-" . date("Y") . " W3Schools.com</p>";
?>
To include the footer file in a page, use the include statement:
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
Hope so you can understand better with my explanations.
A rough 'n' ready way in which you could combine all the stylesheets into one would be to create a php script like below and use that in the html when you load the stylehseet.
<?php
/* all.php */
header( 'Content-Type: text/css' );
$css=array( '/css/header.css', '/css/body.css', '/css/sidebar.css', '/css/footer.css' );
$output=array();
foreach( $css as $file ){
$output[]=file_exists( $file ) ? file_get_contents( $file ) : '/* error: '.$file.' cannot be found */';
}
echo implode( PHP_EOL, $output );
?>
In the html, include the php file rather than a .css file
<link rel='stylesheet' href='/css/all.php' />
In JavaScript there are some solutions to automatically run these kind of tasks. You can install Gulp or any other tasks runner and specifically for CSS concatenation these package gulp-concat-css.
Install:
$ npm install --save-dev gulp-concat-css
Once it is installed you can add a task on your gulpfile.js:
var gulp = require('gulp'),
concatCss = require('gulp-concat-css');
gulp.task('default', function() {
return gulp.src('css/**/*.css')
.pipe(concatCss('css/all.css'))
.pipe(gulp.dest('dist/'));
});
Execute:
$ gulp
Than your html will look like these:
<link type="text/css" rel="stylesheet" href="/dist/css/all.css" />
I'm about an four hours browsing an internet in order to find an answer.
I have an javascript/php/html application with rich functionality.
It includes 3 css files and 5 javascript files.
I want to build it in wordpress page.
I have already made custom page template: checkout.php
Now i need to replace all the stylesheets and javascripts with my own.
I know how to check the template:
<?php if(is_page_template('checkout.php')) :?>
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/stylesheets/main.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/stylesheets/jquery.Jcrop.css" />
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/stylesheets/styles.css" />
<script src="<?php echo get_template_directory_uri(); ?>/javascripts/js_checkout/jquery.min.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/javascripts/js_checkout/jquery-ui.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/javascripts/js_checkout/jquery.Jcrop.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/javascripts/js_checkout/script.js"></script>
I also guess that this functions will add all stylesheets and javascripts to my new template:
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
But do wp_enqueue_style and wp_enqueue_script replaces the default styles and scripts or just add another????
Can some one just tell me how to do this and what file to edit??
header.php or general-template.php??
Thanks in advance alot
Its really going to depend on the theme you are using.
Are you using a child theme?
Where are the existing stylesheets located?
How are those stylesheets and javascript files inserted / injected into the page?
In looking at your existing code, you are correct in assuming that all you are doing at this point, is adding to what already exists on the page.
Do you want to remove all other stylesheets?
What about the existing javascript?
From what you're adding -- it appears to me - you are looking to only add to... as jquery-ui requires jquery
ps don't forget your
<?php endif; ?>
For one time use --- as a programmer I opt for the "simpler the better" method.
The code above would best be added to functions.php within your child theme.
Unless you could benefit from adding additional .js and .css files to other pages... in that case, it would be better to construct a partial. But thats discussion for another time.
Let me know if you need further assistance with this
If you are editing the templates directly, then use your
if(is_page_template///////
to insert the stylesheets, and close it with
}else{ // place default stylesheets here}
If you want to remove ALL the .js files you could use wp_dequeue_script
http://codex.wordpress.org/Function_Reference/wp_dequeue_script
or you could wrap the .js and css inside the same if statement.
Although there are certainly better practices.....
ONE would be the stylesheet --
Why not utilize your if is_template statement to add a new body class and change only the necessary items.
EX: body.cart p{background: red;} would make paragraphs have a red background BUT ONLY on the cart page.