I'm using Drupal 7 and my theme is Omega. I have got a class "mask" and its css code:
.mask {
background:url("../img/header_mask.png") repeat-x scroll 0 0 transparent;
height:200px;
position:absolute;
top:0;
width:100%!important;
z-index:101
}
I'm create a class on Omega theme options for show content top but my div show every page. So, I want show this class only node pages.
This is my node.tpl.php:
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print $user_picture; ?>
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
<div class="content"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
</div>
<?php print render($content['links']); ?>
<?php print render($content['comments']); ?>
</div>
Where add my "mask" class in this code?
If you only want this rule to apply ONLY to node types then change it to:
.node .mask {
...
}
Drupal adds information about the specific node being viewed as well as the node type in a div in the html. You can use Firebug or just viewing the page html to figure out how you may want to restrict your rule based on the classes present for different content types.
If the content type you want this rule to apply to has a machine name of 'event', for example, you'll see that Drupal adds the class 'node-event' to each node of that type, and you can use that to restrict your rule even further:
.node-event .mask {
...
}
Hope that puts you in the right direction!
Related
I'm trying to output content from an Advanced Custom Fields (ACF) in my wordpress theme. At the moment though, all I'm getting is the plain text content from the ACF inside double quotation marks, not inside the div and h1 tags.
The code is copied from another theme I made where it worked, which makes me think something is interfering with it somewhere?
<?php $process_title = the_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>
Thanks to #M.Eriksson, the correct code should be:
<?php $process_title = get_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>
I'm working on a custom template part that includes an h2 with the classes "sectionmarker" and "bodycontent", like this:
<h2 class="sectionmarker bodycontent">Title</h2>
When I call get_template_part() on a page, the output I'm getting is:
<h2 class="bodycontent">Title</h2>
For some reason, it seems not to like "sectionmarker". I even switched the order of the two classes, like this:
<h2 class="bodycontent sectionmarker">Title</h2>
And I get the same output with only the bodycontent class applied. What's going on here?
Full template content:
<?php
$abstract=get_post_field('post_content',224);
$news=get_posts(array(
'post_type'=> 'news'
));
$newsdata=array();
foreach ($news as $n) {
$item=new stdClass();
$item->title=get_the_title($n->ID);
$item->date=get_the_date("",$n->ID);
$item->content=get_field('more_info',$n->ID);
array_push($newsdata,$item);
}
$newsdata_json=json_encode($newsdata);
?>
<script type="text/javascript">
console.log(<?php echo $newsdata_json ?>);
</script>
<?php
echo $abstract;
if(count($newsdata)>0){
?>
<h2 class="sectionmarker bodycontent" >News</h2>
<?php foreach ($newsdata as $newsitem) { ?>
<h4 class='datemarker bodycontent'><?php echo $newsitem->date ?></h4>
<p class='newstext bodycontent'><?php echo $newsitem->title ?></p>
<?php } } ?>
and here's the call I'm making (in home.php):
get_template_part('custom-home-template',null,array());
Nevermind! I just remembered I have some JavaScript that's changing the h2 classes on load.
I would like to detect a certain category with ID=4 and then apply if/else to add div to display contents.
<?php
if (JRequest::getVar('view')=='categories' && JRequest::getVar('id')==4) { ?>
<?php } ?>
How do I achieve this?
I want to show this if the article belongs to category 4 else show another div.
Imagining this two be the different div
<div class="category4">text here</div>
<div class="categoryxxx">text here</div>
Do note that <?php echo $this->item->catid;?> shows the correct Category ID. I would like to apply if and else statement using catid==9 or something. Just not good at PHP.
You can also put directly the html code, avoiding echo. It may useful especially when html code is sizeable.
<?php if ($this->item->catid == 4): ?>
<div class="category4">text here</div>
<!--- any other html code --->
<?php else: ?>
<div class="categoryxxx">text here</div>
<!--- any other html code --->
<?php endif; ?>
Hey I got it working :)
<?php
if ($this->item->catid == 9) {
echo "yes, it exists";
}
else {
echo "no, it don't exist";
}
?>
I was referring the page.tpl.php(Drupal 7 theme) for understanding the code. I found the following code,
<?php if ($site_name || $site_slogan): ?>
<!-- !Site name and Slogan -->
<div<?php print $hgroup_attributes; ?>>
<?php if ($site_name): ?>
<h1<?php print $site_name_attributes; ?>><?php print $site_name; ?></h1>
<?php endif; ?>
<?php if ($site_slogan): ?>
<h2<?php print $site_slogan_attributes; ?>><?php print $site_slogan; ?></h2>
<?php endif; ?>
</div>
<?php endif; ?>
Can you see the code in third line, <div<?php print $hgroup_attributes; ?>> WHY the php code is inside the first div tag of html? Same thing in later part of code also, as you can see h1 and h2 code. So, what is this convention of combining the html and php in so complicated way? and how should I read that?
Combining HTML and PHP code in Drupal templates is actually a very strong feature. In this case, $hgroup_attributes will probably contain some classes that style the div. Printing it in the template results in something like
<div class="SOME_CLASSES"> ... </div>
If you're further interested in the variable $hgroup_attributes, you can inspect by pasting <?php dpm($hgroup_attributes); ?> in your template file after you've installed the Devel module.
I am currently trying to tweak the item.php file into displaying the extra fields separately instead of in a group. I found som code snippets here & there, not really helping as I think they may be outdated.
For instance: This page:
http://steffenjungersen.moloch.dk/nugent-be-goode
I would like "Info" to show on top of the item underneath the bold intro-text.
Also, I would like the "Karakter" (a drop down menu extra field) to display as stars from 1-6
Using the category names I gave these extra fields, I came up with this for the "Karakter" one in item.php:
<?php if(isset($this->item->extra_fields[rating]) && ($this->item->extra_fields[rating] >= 0 || $this->item->extra_fields[rating] <=6)): ?>
<span class="starsbox stars<?php echo $this->item->extra_fields[rating]; ?>"></span>
<?php endif; ?>
And then this in my k2.css file:
.starsbox {
width: 96px;
height: 16px;
display: inline-block;
background: url(images/stars.png) no-repeat;
}
.stars6 {
background-position: 0px 0px;
}
.stars5 {
background-position: -16px 0px;
}
...etc
That didn't work.
Similarly, I tried calling the "Info" field into an independent position and placing it at the top. No reaction.
So i removed the whole item->extra_fields as $key=>$extraField): ?> block and then the extra fields just went away.
Can anyone point me in the right direction here?
Thank you :-)
-astrid
Okay. I got some help from my friends. Here's how far it got us (if anyone should wonder).
In order to have the extra fields displayed independently, you need to split them up. So replace the "foreach ..." line in you item.php with this:
<!-- START: Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
<!-- END: Call to prepare extra fields -->
Then, to call the extra field you need in, do this:
<?php if(isset($extrafields[X]) === true):?>
<?php echo $extrafields[X]; ?>
<?php endif; ?>
Where X is the numeric ID of the extra field.
Now here comes the fun part. I wanted to create a 1-6 stars rating system for my client who is a music journalist. He should be able to select a rating from a dropdown, and this value should be displayed as stars in the item view.
I decided to use the css and sprite based article rating system which comes with K2 - then I could "recycle" the nice star images and the css already created.
Heres how it looks:
<?php if(isset($extrafields[3]) === true):?>
<ul class="itemRatingList">
<li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo round($extrafields[3]*100/6); ?>%;"></li>
<li><?php if(isset($extrafields[3]) == 1):?>1</li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 2):?>2</li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 3):?>3</li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 4):?>4</li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 5):?>5</li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 6):?>6</li><?php endif; ?>
</ul>
<?php endif; ?>
When I at some point can manage to get my hands down, I will look into replacing the a tags with span or something. And I might get around to correcting the text thing. But now it works.
Best regards,
Astrid