News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

How to code load css

Started by Madirex, August 14, 2017, 06:41:22 PM

Previous topic - Next topic

Madirex

I need help with this code:

I like to create something like

if($user_info['is_guest'])

but i need a similar code that do something like:

"If (ID of User) = 1 then load css"

When the user = 1 then load css

Colin

Can you explain what you are trying to accomplish? I think we may be able to provide you some better assistance if we have an overview of what you are trying to do.
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Madirex

Quote from: Colin on August 14, 2017, 07:05:24 PM
Can you explain what you are trying to accomplish? I think we may be able to provide you some better assistance if we have an overview of what you are trying to do.

if($user_info['is_guest'])

Very simple, I want to know which command invokes the user id, to use the function I explained above

If (ID of User) = (ID of User 1)

And the code that I quoted several times what it does is to detect if the user is accessing as a guest, I want to do is to detect the user id number.

d3vcho

Basically, he wants to add a special CSS code (placed in another file) just for the user with ID = x.
"Greeting Death as an old friend, they departed this life as equals"

Madirex

Quote from: d3vcho(); on August 14, 2017, 07:38:12 PM
Basically, he wants to add a special CSS code (placed in another file) just for the user with ID = x.

Yes, I've got it working with

if ($ user_info ['is_guest'])

Now I just have to do something like what I said above, a function that detects the user id, and if the user has x id automatically loads the template

But as I do not understand neither functions nor PHP I do not know how to do it

Arantor

Loads the template or loads the CSS?

Madirex

Quote from: Arantor on August 15, 2017, 03:23:16 AM
Loads the template or loads the CSS?
I just need a code that detects the id of the user and if it is x id I will execute the code that I have already created.

I have already created the rest of the code, I have tried and it works

if($user_info['is_guest'])
loadTemplate('BlogTemplate2');
else
loadTemplate('BlogFeatures');


Just change the code "if($user_info['is_guest'])" to something like "if $user_info = 1 then"

Illori

are you using SMF 2.1 or SMF 2.0?

Madirex

Quote from: Illori on August 15, 2017, 05:00:37 AM
are you using SMF 2.1 or SMF 2.0?
Hello, im using 2.0.14
I think I published this issue in 2.0.14 D: I do not know who moved it or if it was an oversight of mine

Shambles

Have you looked into the whole $user_info array?

Eg   if($user_info['id']==1)

Madirex

Quote from: Shambles on August 15, 2017, 06:05:40 AM
Have you looked into the whole $user_info array?

Eg   if($user_info['id']==1)

I can not get it to load the code css, only the .template file, i try to use loadTemplate('templatefile','cssfile'); but nothing

Madirex

Quote from: Madirex on August 15, 2017, 07:27:58 AM
Quote from: Shambles on August 15, 2017, 06:05:40 AM
Have you looked into the whole $user_info array?

Eg   if($user_info['id']==1)

I can not get it to load the code css, only the .template file, i try to use loadTemplate('templatefile','cssfile'); but nothing
any idea?

Madirex

Bump

I want to use this code

if($user_info['is_guest'])
   loadTemplate('BlogTemplate2');
else
   loadTemplate('BlogFeatures');


but no template, i want css and i dont want is_guest i want a url detector, if blog = 1 then loadcss

bestnow

are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

Madirex

Quote from: bestnow on August 21, 2017, 06:34:27 PM
are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

I need to detect player id of the url of user

bestnow

Quote from: Madirex on August 21, 2017, 06:57:20 PM
Quote from: bestnow on August 21, 2017, 06:34:27 PM
are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

I need to detect player id of the url of user

not sure if i get u but if u want one css for guest and one css for logins here is what a come up with



<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($user_info['is_guest'])
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index_guest'$context['theme_variant'], '.css?fin20" />';
  }
   elseif (
$user_info['is_guest'] == "0")
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index'$context['theme_variant'], '.css?fin20" />';
  }
  
?>




Madirex

Quote from: bestnow on August 21, 2017, 07:58:32 PM
Quote from: Madirex on August 21, 2017, 06:57:20 PM
Quote from: bestnow on August 21, 2017, 06:34:27 PM
are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

I need to detect player id of the url of user

not sure if i get u but if u want one css for guest and one css for logins here is what a come up with



<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($user_info['is_guest'])
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index_guest'$context['theme_variant'], '.css?fin20" />';
  }
   elseif (
$user_info['is_guest'] == "0")
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index'$context['theme_variant'], '.css?fin20" />';
  }
  
?>



Hello, i want to change this end of the code:
//Load Html Headers
$context['html_headers'] = '
<script type="text/javascript"><!-- // --><![CDATA[
var smf_blog = "'.$boardurl.'/blog/ajax/";
var smf_blog_text = "'.$txt['blog_like_thanks'].'";
// ]]></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/jquery.js"></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/adk_blog.js"></script>
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';


(the end line: <link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />)
to something like:
If $context['blog']['id_user'] = 1 then
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />
else
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />

bestnow

Quote from: Madirex on August 21, 2017, 08:01:04 PM
Quote from: bestnow on August 21, 2017, 07:58:32 PM
Quote from: Madirex on August 21, 2017, 06:57:20 PM
Quote from: bestnow on August 21, 2017, 06:34:27 PM
are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

I need to detect player id of the url of user

not sure if i get u but if u want one css for guest and one css for logins here is what a come up with



<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($user_info['is_guest'])
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index_guest'$context['theme_variant'], '.css?fin20" />';
  }
   elseif (
$user_info['is_guest'] == "0")
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index'$context['theme_variant'], '.css?fin20" />';
  }
  
?>



Hello, i want to change this end of the code:
//Load Html Headers
$context['html_headers'] = '
<script type="text/javascript"><!-- // --><![CDATA[
var smf_blog = "'.$boardurl.'/blog/ajax/";
var smf_blog_text = "'.$txt['blog_like_thanks'].'";
// ]]></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/jquery.js"></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/adk_blog.js"></script>
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';


(the end line: <link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />)
to something like:
If $context['blog']['id_user'] = 1 then
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />
else
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />

little hard for me to test if its work but here

<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($context['blog']['id_user']=="1")
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />';
  }
   else 
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';
  }
  
?>


Madirex

Quote from: bestnow on August 21, 2017, 08:11:11 PM
Quote from: Madirex on August 21, 2017, 08:01:04 PM
Quote from: bestnow on August 21, 2017, 07:58:32 PM
Quote from: Madirex on August 21, 2017, 06:57:20 PM
Quote from: bestnow on August 21, 2017, 06:34:27 PM
are u asking for css to load for

1.guest
2.login
3. admins

or are u looking for specific id
from profile?

I need to detect player id of the url of user

not sure if i get u but if u want one css for guest and one css for logins here is what a come up with



<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($user_info['is_guest'])
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index_guest'$context['theme_variant'], '.css?fin20" />';
  }
   elseif (
$user_info['is_guest'] == "0")
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'$settings['theme_url'], '/css/index'$context['theme_variant'], '.css?fin20" />';
  }
  
?>



Hello, i want to change this end of the code:
//Load Html Headers
$context['html_headers'] = '
<script type="text/javascript"><!-- // --><![CDATA[
var smf_blog = "'.$boardurl.'/blog/ajax/";
var smf_blog_text = "'.$txt['blog_like_thanks'].'";
// ]]></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/jquery.js"></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/adk_blog.js"></script>
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';


(the end line: <link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />)
to something like:
If $context['blog']['id_user'] = 1 then
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />
else
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />

little hard for me to test if its work but here

<?php 
//------------------------------------------------------------------------------------------------------------+
/* CHANGE CSS STYLE   */ //GUEST,LOGIN AND ADMINS
  
if ($context['blog']['id_user']=="1")
  {
  echo 
'<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />';
  }
   else 
  {
    echo 
'<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';
  }
  
?>


but i can't put into:

//Load Html Headers
   $context['html_headers'] = '

:(

TehCraw

This should work for you.

Code (php) Select

// Load Html Headers
$context['html_headers'] .= '
<script type="text/javascript"><!-- // --><![CDATA[
var smf_blog = "'.$boardurl.'/blog/ajax/";
var smf_blog_text = "'.$txt['blog_like_thanks'].'";
// ]]></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/jquery.js"></script>
<script type="text/javascript" src="'.$boardurl.'/blog/js/adk_blog.js"></script>';

if ($context['blog']['id_user'] == 1) {
$context['html_headers'] .= '
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/blog1.css" />';
} else {
$context['html_headers'] .= '
<link rel="stylesheet" type="text/css" href="'.$boardurl.'/blog/css/adk_blog.css" />';
}
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. - Martin Fowler

Advertisement: