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);
}
Related
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 ?
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; ?>
I want to display name of multiple authors on the front end like below
By John Doe,Linn Doe and Penny
In the back end I can add many users for the same post.But In the front end only the first author on the post shows up both for the byline and the bio. I'm using Twenty Thirteen theme and how to show all the user added in the back end in the front end?
this is my single.php file
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php twentythirteen_post_nav(); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Incorporate Co-Authors Plus template tags into your theme
Other Solution:
In order to add add Co-Authors Plus support you must have access to edit the theme template. In order to display information about multiple authors on the fronted, you'll need to add the necessary Co-Authors Plus template tags to your single.php and other theme files.
Specifically for the bylines, you'll want to replace where it says something like:
<?php the_author(); ?>
With something like this:
<?php if ( function_exists( 'coauthors' ) ) { coauthors(); } else { the_author(); } ?>
That specific snippet will allow your theme to degrade gracefully when Co-Authors Plus isn't activated.
To show the authors with their posts link, you'll want to use something like:
<?php if ( function_exists( 'coauthors_posts_links' ) ) { coauthors_posts_links(); } else { the_author_posts_link(); } ?>
You can use the following code for the bios
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ): ?>
<center><div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $coauthor->user_firstname; ?>.jpg" alt="" class="alignleft"/>
<?php $userdata = get_userdata( $coauthor->ID ); ?>
<?php if ( $userdata->user_description ) echo $userdata->user_description; ?>
</div></center>
<?php endforeach; ?>
Reference
i'm trying to build a navigation for a website, and i'm struggling with it. I'm trying to make a foldable navigation that shows only categories at first, when clicked, they link to the category, and show current category posts only.
I came this far:
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo '<h2><a href="./?cat='.$cat->term_id.'">'.$cat->name.'</h2>';
// create a custom wordpress query
query_posts("cat=$cat_id");
// start the wordpress loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<?php the_title(); ?><br>
<?php endwhile; ?> <?php endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
The problem with this is: when i fill in the query so that it only takes the current cat, it displays current cat posts on both my categories.
this is what i want for the nav actually:
graphic design
Other Projects
when clicked on graphic design:
graphic design
Project 1
Project 2
Other Projects
when clicking on Other projects:
graphic design
Other Projects
Project 1
Project 2
so basically:
- when clicking from Index page to a category, only that category should expand
- when clicking the other category, the current category changes, so the previous category collapses and the other one expands.
and a bonus: is it possible, that when on a single post, there expands another level of info? for example, a few custom fields per post. like this:
graphic design
Other Projects
Project 1
custom field 1
custom field 2
…
Project 2
thank you very much
Try this code
<?php $article_categories = get_categories(array(
'child_of' => get_category_by_slug('graphic design')->term_id
));
$talentChildren = get_categories(array('child_of' => get_category_by_slug('Project 1')->term_id));
?>
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : ?>
<div class="post-list">
<?php foreach($talentChildren as $talent): ?>
<?php
$talentSubChildren = new WP_Query();
$talentSubChildren->query(array('category_name' => $talent->slug));
?>
<h2><?php echo $talent->name; ?></h2>
<ul>
<?php while ($talentSubChildren->have_posts()) : $talentSubChildren->the_post(); ?>
<li>
<?php talent_thumbnail(); ?>
<h4>
<?php the_title(); ?>
</h4>
<p><?php the_excerpt(); ?></p>
read on »
</li>
<?php endwhile; ?>
</ul>
<?php endforeach; ?>
<?php if($wp_query->max_num_pages!=1):?>
<div class="pagination">
<?php previous_posts_link('« prev') ?>
<span class="current"><?php echo $wp_query->query['paged']; ?></span>
of <span class="total"><?php echo $wp_query->max_num_pages; ?></span>
<?php next_posts_link('next »') ?>
</div><!-- .pagination -->
<?php endif; ?>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div>
Ive gotten a bit further, but i need some help now.
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo '<h2><a href="./?cat='.$cat->term_id.'">'.$cat->name.'</h2>';
// create a custom wordpress query
query_posts("cat=$cat_id"); ?>
<?php if (in_category($cat_id)) { ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<?php the_title(); ?><br>
<?php endwhile; ?> <?php endif; // done our wordpress loop. Will start again for each category ?>
<?php } else { ?>
<?php } ?>
<?php } // done the foreach statement ?>
So this is working now: it lists the posts per category, if in the current category, else it doesnt show anything.
now what i still want: i want to add something extra within the loop IF i'm on a single page. I have this code:
<?php wp_reset_query(); ?>
<?php if (is_single('84')) { ?>
Yes
<?php } else { ?>
no
<?php } ?>
But that would mean i have to break a query in the middle of a loop. and the is_single thing does not work inside a loop / without the query reset.
I want it looking like this with above code:
Graphic Design
project 1 (for example id=84)
Yes
project 2 (for example id=101)
No
thanks
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.