views:

64

answers:

2

How do I change the link href to css, js code for each article without manually doing it? Each article I write is seperated into different folders and I start each article with one template that links to css/reset.css etc.

This is my sample article template code: Sample Article Page

 <link href="css/slider.css" rel="stylesheet" type="text/css" media="screen" />
 <!-- jquery -->
 <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js"&gt;&lt;/script&gt;
 <!-- superfish -->
 <link href="css/superfish.css" rel="stylesheet" type="text/css" media="screen" />
 <script type="text/javascript" src="js/hoverIntent.js"></script>
 <script type="text/javascript" src="js/superfish.js"></script>
 <!-- initialize jquery superfish plugins -->
 <script type="text/javascript" src="js/init.js"></script>
 <!-- tabs -->
 <script src="js/ui.core.js" type="text/javascript"></script>
    <script src="js/ui.tabs.js" type="text/javascript"></script>
 <link rel="stylesheet" href="css/ui.tabs.css" type="text/css" media="screen" />
 <!-- initialize tabs -->
 <script type="text/javascript">
  $(document).ready(function(){
   $('#container-1 > ul').tabs(); /* news and events */
   $('#container-2 > ul').tabs(); /* pre-footer tab */
   $('#container-4 > ul').tabs(); /* popular items */
+2  A: 

It sounds like you're asking how you can use the same URL for each external file, regardless of where your page is placed.

If so, all you would need is to use absolute URLs instead of relative URLs. That is, "/foo/bar/reset.css" (note the initial slash) instead of "bar/reset.css"

Absolute URLs trace from the site root, rather than the file's current location, and so the links will be the same regardless of where you place the file.

Edit:

You would put this URL in the same place where you already put the relative URLs: That is:

<link type="text/css" rel="stylesheet" media="all" href="/foo/bar/style.css" />

instead of the

<link type="text/css" rel="stylesheet" media="all" href="bar/style.css" />

that you are using now.

anschauung
okay i kinda understand it :Dbut what is foo or bar?
Kevin Li
@Kevin: 'Foo' and 'bar' are generic placeholders for text. They don't mean anything special, but most coders would recognize them as meaning "put your info here" In this case, '/foo/bar' is basically the same as writing '/whatever/your/folders/are/called'
anschauung
and also i format it like this:<link href="foo/bar/css/style.css" rel="stylesheet" type="text/css" media="screen" />
Kevin Li
i really still don't get it: My articles are placed like this /observer/articles/october...My css is like this /observer/csshowever in dreamweaver its already connected to my server so it just places the css like /css/etc.etc.
Kevin Li
so how do i linkhref each article to my site root /css?
Kevin Li
@Kevin: Do you mean that you put the "href" parameter first? If so, that's okay. The order of the statements usually doesn't matter at all -- use whatever is easiest for you to maintain.
anschauung
and why is there an extra foo if they are placeholder texts? what if i only have /bar (one folder)?
Kevin Li
@Kevin: Don't get too hung up on the particulars of 'foo' and 'bar'. I only used them because it's easier to write an example that way. Your own settings will differ :)
anschauung
Okay so what is the difference between absolute and relative?
Kevin Li
@Kevin: Look closely at your sample code: Your links are relative (href="css/slider.css") since they don't have an initial slash. If you adjust them to href="/css/slider.css" then you will have absolute links.
anschauung
okay thank u soooo much i got it :D
Kevin Li
@Kevin: Relative links "start" from where the file resides. Absolute links "start" from your site root.
anschauung
@Kevin: Sure thing :)
anschauung
A: 

Kevin, correct me if I'm wrong; you have a series of html files in different folders and you want to update all of the CSS and javascript links in them to point to a new location.

Your scenario:

wwwroot/
       |
       -- CSS/
             |
             -- reset.css
       |
       -- Javascript/
       |
       -- 20090112/
                  |
                  -- file1.html
       |
       -- 20090207/
                  |
                  -- file2.html
                  -- file3.html
       |
       -- etc.

Dreamweaver is placing everything in your CSS folder. If you want to keep the CSS files there then you need to specify correct relative paths, or else use absolute paths.

An absolute path is one that specifies the exact location of the file http://www.somedomain.com/css/reset.css is an absolute path.

A relative path defines the path from the location of the current file. So if you wanted to add reset.css to file1.html you would specify its location in this manner ../css/reset.css

Broken down this path specifies:

..           up one folder [we're now in wwwroot]
/css         the path from wwwroot
/reset.css   the filename

Does this help?

Sean Vieira