position of the drupal module inside the header - css

i m new to Drupal 7 and in this forum, please be nice :)
I m trying to customize a bit the drupal module "On the web" (that display facebook and youtube link button). This module work great but I would like to to modify the position of the social images provided by this module inside a sub theme of Zen. I could be nice to put it at the left-top the header region.
As it says in the documentation I :
1)
Place the following code in the template.php file in your theme, and replace 'mytheme' with the name of your theme:
/**
* Overrides theme_on_the_web_image().
*/
function mytheme_on_the_web_image($variables) {
return $variables['service'];
}
2) I add this line : <div id="myidtomodifythecssafter"> <?php print $service; ?></div> in the page.tpl.php like following :
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan">
<div id="myidtomodifythecssafter"> <?php print $service; ?></div>
<?php if ($site_name): ?>
<?php if ($title): ?>
<div id="site-name"><strong>
<span><?php print $site_name; ?></span>
</strong></div>
<?php else: /* Use h1 when the content title is empty */ ?>
<h1 id="site-name">
<span><?php print $site_name; ?></span>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php if ($site_slogan): ?>
<div id="site-slogan"><?php print $site_slogan; ?></div>
<?php endif; ?>
</div><!-- /#name-and-slogan -->
<?php endif; ?>
3) I cleared the cache
but then the module images don't appear and i got this error in the front page :
Notice: Undefined variable: service in include()
i don't understand, what did I miss ?

Ok after reading the module code :
The function zhongdao_on_the_web_image is for theming the rendering of your anchor tags. Not really what you want here, so you can remove it.
This module create a block (under admin > structure > bloc) that you can position anywhere in your theme regions, then up to you to style it differently with CSS.
But if you want to render the block content another solution is this one :
https://www.drupal.org/node/26502
Wich will translate to something like this :
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan">
<div id="myidtomodifythecssafter">
<?php
$block = module_invoke('on_the_web', 'block_view', 0 /* might want to change depending of your block*/);
print render($block['content']);
?>
</div>
<?php if ($site_name): ?>
<?php if ($title): ?>
<div id="site-name"><strong>
<span><?php print $site_name; ?></span>
</strong></div>
<?php else: /* Use h1 when the content title is empty */ ?>
<h1 id="site-name">
<span><?php print $site_name; ?></span>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php if ($site_slogan): ?>
<div id="site-slogan"><?php print $site_slogan; ?></div>
<?php endif; ?>
</div><!-- /#name-and-slogan -->
<?php endif; ?>

Related

Drupal lost css when comment fail

On my node page I have the comment form that I've stylised in CSS, the problem is that when I submit this form and the form throw an error all my css disapear, I think this is my whole wrapper who disapear (a div that I set in the wrapper template is gone)
Also the comment block go to the bottom of the page, just before the footer
Here is my wrapper, for the comment I don't do something special it's just the default one
<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php if ($content['comments'] && $node->type != 'forum'): ?>
<?php print render($title_prefix); ?>
<h2><?php print t('Avis de nos clients'); ?></h2>
<?php print render($title_suffix); ?>
<?php endif; ?>
<?php print render($content['comments']); ?>
<?php if ($content['comment_form']): ?>
<h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
<?php print render($content['comment_form']); ?>
<?php endif; ?>
</div>
What can I do ?

How to separate view custom link/url from view content

I override block using these technic https://www.drupal.org/node/1089656.
<div id="<?php print $block_html_id; ?>" class="footer-links-regions <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div class="g4_20 tgfull">
<?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
<h3<?php print $title_attributes; ?>><?php print $block->subject ?></h3>
<?php endif;?>
<?php print render($title_suffix); ?>
</div>
<!-- CONTENT -->
<div class="g16_20 tgfull mhidden" <?php print $content_attributes; ?> >
<?php print $content ?>
</div>
</div>
Then I added custom link via admin and Custom URL (Link display). I realized that I can see this link inside content (I mean that this link is added to $content). I would like to handle this link and real content separately.

Where is wordpress search page content generated?

I'm trying to style a search page in wordpress. In search.php I can style most of the page but then the following statement (which I got from the original uneditted page) generates the content.
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
This ALMOST displays the page as I want it, but there are a few elements off the page, making it expand etc. I can't figure out what file is generating this content!
Using the instructions I created a content-search.php and change the line of code to this...
get_template_part( 'content', get_post_format() );
Which works...but it doesn't display much of anything because I don't know what to put in my page within seeing the original.
Anyone have any clue?
You can use a template part named post-search.php and can use it inside your search.php file like
get_template_part( 'post' , 'search')
but you have to create a php file inside your theme folder and name it post-search.php and inside this file just put the WordPress' loop i.e.
<?php while (have_posts()) : the_post(); ?>
<div class="post-entry clearfix"> <!-- Main wrapper -->
<div class="post-entry-content"> <!-- Post-entry-content -->
<h2><?php the_title(); ?></h2>
<div class="post-entry-date">Posted on <?php the_time('F Y') ?> with <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
<?php the_excerpt(); ?>
Read More ?
</div><!-- END of post-entry-content -->
</div><!--End of main wrapper -->
<?php endwhile; ?>
and your search.php could be something like this
<?php get_header(' '); ?>
<div id="post-wrap">
<div id="post-content">
<?php if (have_posts()) : ?>
<?php get_template_part( 'post' , 'search') ?> // This will load/include the file post-search.php and result will be displayed as formatted in this file
<?php else : ?>
<p>Sorry, it does not exist !</p>
<?php endif; ?>
</div><!-- END post-conten -->
<?php get_sidebar(' '); ?>
</div><!-- END post-wrap -->
<?php get_footer(' '); ?>
This is just an example, change div/h2 id/class names according to your theme css.
Note: I'm currently using this approach in one of my site and I've one file named 'post-entry.php' in my theme folder and in my every template file (index.php, search.php e.t.c) I just use this file by calling
<?php get_template_part( 'post' , 'entry') ?>

Modify global wp_query to return latest of custom post type

I have developed a theme with custom post types. One of those post_types is called events.
I wan't to display the latest event in a "page" called "upcoming event". So i created this template file called "Events". Now i need to modify the global wp_query so that i return this last event.
This is how my single.php looks like:
<?php
get_header();
setup_postdata($post);
get_page_post_content();
get_footer();
?>
Works fine when viewing event as custom posts types "normal". And this is my template file which should contain the latest event:
<?php
/*
* Template Name: Event
*/
?>
<?php
global $wp_query;
$wp_query = new WP_Query('post_type=event&posts_per_page=1');
include 'single.php';
?>
However this does not work as expected since i have other parts of my template depending on properies like "is_single()" which is this case returns false, since the query is called from a page. I somehow need to set the query so those properies are changed. Anyone knows how or how i should solve this?
Thanks!! :D
Put below code in your template file.
<?php
/**
Template Name: Event
*/
get_header();
?>
<div id="content" >
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts('post_type=event&paged='.$paged.'&posts_per_page=10');
if (have_posts ()) :
while (have_posts ()) : the_post(); ?>
<div <?php post_class() ?>>
<div class="post-title">
<h2 class="alignleft"><?php the_title(); ?></h2>
</div><!-- .post-title -->
<div class="post-content">
<?php the_excerpt('read more');?>
</div>
</div><!--end of .post_class -->
<div class="post-meta">
<p class="alignright"><a class="readmore" title="<?php get_the_title();?>" href="<?php echo get_permalink( $post->ID );?>" rel="nofollow">Read</a></p>
<span class="alignright comment-cnt"><?php comments_popup_link( 'No Comments', '1 Comment', '% Comments' ); ?></span>
<div class="clear"></div>
</div><!-- end of .post-meta -->
<?php
endwhile;
endif;
?>
</div>
<div class="clear"></div>
</div>
<?php get_footer(); ?>

Drupal: modify default homepage to strip html from nodes

I have nodes being displayed as 'promoted to homepage'. The nodes body can contain basic html which is fine for that nodes page but when not for the homepage. Is there any way to modify this to strip any html tags?
Thanks,
Jonesy
The common way to handle this would be to just replace the default home page with a view from the Views module.
Just create a view to list nodes (title/body/post date/whatever), filter by "promote to front page", and check the "strip html" checkbox for the body field.
You can handle this in the theme template. In your theme folder, create or edit node.tpl.php. What it will need to look like will depend on what specifically your node template contains, but with the default template it would be something like this:
<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 $node_title; ?></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($display_submitted || !empty($content['links']['terms'])): ?>
<div class="meta">
<?php if ($display_submitted): ?>
<span class="submitted">
<?php
print t('Submitted by !username on !datetime',
array('!username' => $name, '!datetime' => $date));
?>
</span>
<?php endif; ?>
<?php if (!empty($content['links']['terms'])): ?>
<div class="terms terms-inline"><?php print render($content['links']['terms']); ?></div>
<?php endif; ?>
</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']);
if ($is_front) {
print strip_tags(render($content));
} else {
print render($content);
}
?>
</div>
<?php print render($content['links']); ?>
<?php print render($content['comments']); ?>
</div>
Note, I haven't tested this at all, but if your theme is using the default node template (there is no node.tpl.php in your theme), then you should be able to just drop this in.
The key line is:
if ($is_front) {
print strip_tags(render($content));
} else {
print render($content);
}

Resources