How to separate view custom link/url from view content - drupal

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.

Related

How can I retrieve an ACF field from a custom post type to the archive page of this CPT?

I create a Custom Post Type with ACF field inside. Everything works great, but when I want to create my archive-cpt.php page, I can't get my ACF field to be seen on this page.
Here is my archive page code :
<?php get_header(); ?>
<main role="main">
<!-- section -->
<section>
<h1><?php _e( 'Archives', 'trad' ); ?></h1>
<div class="container">
<div class="row">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="col-lg-4 mx-auto">
<!-- article -->
<h2 class="titre-extranet-article">
<?php the_title(); ?>
</h2>
<li>
<?php // display a sub field value
get_sub_field('titre'); ?></li>
</div>
<!-- /post thumbnail -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'trad' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
</div>
</div>
<?php get_template_part('pagination'); ?>
</section>
<!-- /section -->
</main>
<?php get_footer(); ?>
The sub field 'titre' doesn't appear on my archive page.
Where I am wrong ?
Thank you.
get_sub_field() is for a repeater field. So you need to get the parent first e.g.
if( have_rows('parent_field') ):
while ( have_rows('parent_field') ) : the_row();
$titre = get_sub_field('titre');
// Do something...
endwhile;
endif;
You can get that field just with get_field() if it is a single text field.
Try with get_field()
<?php echo get_field('titre'); ?>
And one more thing you forgot to add echo before the get_sub_field(). So try with the echo.
<?php echo get_sub_field( 'titre' ); ?>

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

Custom content rendering with $page content

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

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