Drupal Front Page Markup

Go To StackoverFlow.com

0

I'm trying to change the markup around articles being displayed on the front page of a drupal site so I can integrate them into a slideshow. (I can't use a slideshow module). I have a page--front.tpl.php file, but I need to add more specific markup than I can do here.

How do you go about changing the markup for just a specific area of the front page?

I believe I need to write a preprocess hook, but I'm not sure how to target just the articles node on the front page. This is the markup I would like to have generated:

<div class="slidewrap" data-autorotate="5000">
    <ul class="slidecontrols">
        <li><a href="#sliderName" class="next">Next</a></li>
        <li><a href="#sliderName" class="prev">Prev</a></li>
    </ul>
    <ul class="slider" id="sliderName">
        <li class="slide">  
            <h2 class="slidehed">First Slide</h2>
            <img src="1.jpg" />
            <p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget, scelerisque a libero.</p>
        </li>
        <li class="slide">  
            <h2 class="slidehed"><a href="#">Second Slide</a></h2>
            <img src="2.jpg" />
            <p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</p>
        </li>
        <li class="slide">  
            <h2 class="slidehed">Third Slide</h2>
            <img src="3.jpg" />
            <p>Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget.</p>
        </li>
        <li class="slide">  
            <h2 class="slidehed"><a href="#">Fourth Slide</a></h2>
            <p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio.</p>
        </li>
        <li class="slide">  
            <h2 class="slidehed">Fif' Slide</h2>
            <p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</p>
        </li>
    </ul>
</div>

I've been trying to do this using the views module. However, when I create a new template I get this error message: Warning: Invalid argument supplied for foreach() in include() (line 12 of /d7install/path_to_theme/views-view--featured--block.tpl.php).

Here is the template file that I copied via the Theme Information:

<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes_array[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
2012-04-04 18:48
by TucsonLabs
What's your question - ghoti 2012-04-04 18:52
How do I change the markup for the front page? I would like to know how to either write a preprocess hook to add markup that just targets the articles or how to do this in a template file. I would prefer the former because that seems to be the standard method in drupal, however either would be sufficient - TucsonLabs 2012-04-04 20:32
You are not providing enough information. What are you trying to achieve exactly. Saying you want to target articles isn't enough information. What do you want to do with the articles? Why is page--front.tpl.php not enough for you? Please be more specific with your questions - jsheffers 2012-04-05 00:31
I'm not sure why that wasn't specific enough, but I've added roughtly the markup I would like generated to my question. Basically I would like the title, and an excerpt with an image displayed. The image could be within the

tag or displayed before it. Thanks for your help - TucsonLabs 2012-04-05 17:45

Is that the full file? It says error on line 12 but you've only pasted 8 lines - jsheffers 2012-04-05 21:05
No, there are comments above it. Sorry about that. This is line 12: TucsonLabs 2012-04-05 21:27


0

there is a simple solution. Add a new template for article content types. node-article.tpl.php. And then add an if statement to that, if the article is on the front page, show markup A, else show markup B. Like:

if (drupal_is_front_page()) {
    <article class='front-page'>Article</article>
}
else
{
    <article class='other-page'>Article</article>
}
2012-04-06 02:58
by Joshua Kissoon


-1

This can all be achieved by the views module: http://drupal.org/project/views

Create a block display and have it show only on the home page. There should be no need for a custom views template.

You can add the .slidercontrols UL to the header of the view. Also if you need the attribute on the outer div just add it via jQuery with something like this.

$('.slidewrap').attr('data-autorotate', 5000);
2012-04-05 20:43
by jsheffers
I mentioned that I was using the views module and getting an error. I want to use a template to edit the markup. I'm going to need to change markup in template files besides just the home page also, so your answer isn't really helpful. I find it hard to believe that a module is needed for something so trivial. Isn't their a way to do this with the core files? By "core" I mean template files to edit core functionality - TucsonLabs 2012-04-05 20:53
My answer said there is no need for the template views-view--featured--block.tpl.php just remove that template and use views like normal - jsheffers 2012-04-05 20:55
well thanks for your help. I would like to be able to edit a template file and not have to rely on a setting in a database - TucsonLabs 2012-04-05 20:57
If you want help with the template file, please paste in the code and I'll take a look - jsheffers 2012-04-05 20:58
I've update the question with the code which I just copied and pasted from the Theme Information overlay - TucsonLabs 2012-04-05 21:05
This tutorial might help you: http://www.wdtutorials.com/drupal7/4 - jsheffers 2012-04-05 21:08
Thanks, but that tutorial really doesn't help. I'm getting an error on this line. The template file works, I just can't loop through the data I'd like to - TucsonLabs 2012-04-05 21:20
And you got that template suggestion from the theme information? Is views-view--featured--block.tpl.php what it recommends and did you copy the code from that specific template - jsheffers 2012-04-05 21:35
yes that's what it recommends and I just copied it after I clicked on "style output". I've tried other template names as well - TucsonLabs 2012-04-05 21:39
Ads