Custom content rendering with $page content - drupal

I created a custom content type, and a view for it.
My page.tpl.php has the following
<div class="<?php print (drupal_is_front_page()) ? 'frontBox' : 'container contBox'; ?>">
<div class="<?php print ($page['categories_blog'] || $page['recent_blog'] || $page['recent_comments']) ? 'globalContant span9' : 'gCont'; ?>">
<?php print render($page['content']); ?>
<?php if ($page['contact_info']): ?>
<div id="contactInfo">
<?php print render($page['contact_info']); ?>
</div>
<?php endif; ?>
</div>
so I have set up my custom content similar to other template objects and they do not get render with the page['content'] yet the one I created gets rendered.
Drupal being so obsfucated is frustrating the hell out of me

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 ?

position of the drupal module inside the header

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; ?>

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.

WordPress: next_posts_link() doesn't work before page template loop

I have an archive page template that I've built that has a successful navigation at the end of the loop. However, now I want to add an additional navigation at the top. However, after I copied and pasted the exact code, the 'Previous Entries' displays and links correctly, but 'Next Entries' never shows up as it does in the bottom navigation.
In my page-archive.php file, this is gist of my code:
<div class="navigation top">
<?php next_posts_link('Next Entries') ?> <!-- Doesn't appear to show up! -->
<?php previous_posts_link('Previous Entries') ?>
</div>
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=1&paged=$page");
while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h3><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></h3>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation bottom">
<?php next_posts_link('Next Entries') ?>
<?php previous_posts_link('Previous Entries') ?>
</div>
I understand that a Page template is not the ideal method to create an archive page, so if there is a different method for producing a full customizable archive page, please inform me!
Currently, I'm using my home.php file to display static content, so the page-archive.php is a method to direct users to the actual "Blog" portion of the site.
Try to put this string:
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=1&paged=$page");?>
to the very top of the page. You need to do that because next_posts_link and prev_posts_link calls use some global variables set by query_posts call.

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(); ?>

Resources