How to show CCK field in search result? - search

How to display custom CCK field (text or imagefield) in Drupal core search results page?

You need to override search-result-tpl.php in your theme. Copy it from modules/search to your themes directory, clear the theme cache, and you're set. You'll see that there is an array available to the theme file called 'result', which contains a bunch of data, including a node object. So your file becomes something like:
<dt class="title">
<?php print $title; ?>
</dt>
<dd>
<?php
// Here is the change
print $result['node']->field_name_of_cck_field['view'];
?>
<?php if ($snippet) : ?>
<p class="search-snippet"><?php print $snippet; ?></p>
<?php endif; ?>
<?php if ($info) : ?>
<p class="search-info"><?php print $info; ?></p>
<?php endif; ?>
</dd>
Good luck!

1 Copy search-result.tpl.php file from modules/search to your theme folder
2 For CCK text field add:
<?php if ($result['node']->field_name[0]['value']): ?>
<h4><?php print($result['node']->field_name[0]['value']); ?></h4>
<?php endif; ?>
3 For imagefield with imagecache:
<?php if ($result['node']->field_logo[0]['filename']): ?>
<img src="/sites/default/files/imagecache/path_to_file/<?php print $result['node']->field_logo[0]['filename']; ?>" />
<?php endif; ?>
4 CSS styling next.
Thanx for cam8001 & googletorp!

It depends how you do the search.
If you use views to build a search, you can decide yourself what to show.
If you're using some other search mechanics, you can use a combination of a proprocess hook, theming function, template you get the output you want. You should have the node object available, so displaying a CCK should be easy enough.
Edit:
For the Drupal core search module you need to overwrite the search-result.tpl.php in your theme, to alter how search results are printed. Here you can add or delete info. If you need more variables, you can create them for use in the template in a process hook. This is basic Drupal theming, check out the handbook.

Related

How to open a view inside a view with CodeIgniter 4?

I am new with CodeIgniter 4. At CodeIgniter 3 we can use a view inside another view like this :
<head>
<?php this->load->view("containers/head"); ?>
</head>
But same is not working with CodeIgniter 4 and I couldn't find it. Any suggestions?
Have a great day!
Okay, for those who may search this, I used this and it worked.
<head>
<?php echo view("containers/head"); ?>
</head>
I recommend that you read the documentation.
View Layouts in CI4
My view layout template layout.php
[...]
<head>
<?= $this->renderSection('head')?>
</head>
[...]
My view
<?= $this->extend('layout') ?>
<?= $this->section('head') ?>
<!-- Code in block <head> -->
<?= $this->endSection('') ?>
It may also be helpful: View Parser in CI4

How can I echo visual swatch on a phtml Magento 2

I would like to please your help.
I want to echo an attribute that I created Brand which is a Visual swatch (i use Ajax Layered Navigation, so I have an option with text and Swatch image).
I manage to echo each product the brand text that belongs but I can't echo the image.
Can you please help me?
<?php $attributeValue = $_product->getAttributeText('manufacturer'); ?>
<?php if(strlen($attributeValue) > 0): ?>
<?php echo $attributeValue; ?>
<?php endif; ?>

How to render page elements from hook_form_alter() drupal 6?

I need to render contact form field elements using form_alter function.
When I print $content variable in tpl file, the contact form loads entirely, instead of that I need to render fields separately like drupal_render(drupal_get_form(form['name'])).
For Drupal 7, you can refer to /modules/node/node.tpl.php as an example. Here is a code snippet in the file:
<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']);
print render($content);
?>
</div>
<?php print render($content['links']); ?>
<?php print render($content['comments']); ?>
I'm not sure if there is difference in Drupal 6, but you can try.

areablock in block is not working properly

as i understand, nested areablock are possible since long. but something's not working.
lets say we have two areas, one called 'nested' and one called 'text'.
this is view.php for text:
<div>
<?php echo $this->wysiwyg("content_wysiwyg"); ?>
</div>
this is view.php for 'nested':
<div>
<?php while($this->block('index')->loop()) { ?>
<div>
<?php echo $this->areablock('index_block'); ?>
</div>
<?php } ?>
</div>
i create a page, and insert the areas like this:
nested 1
text 1
nested 2
text 1.1
when i preview the page everything is fine. but when i view the same page without pimcore_preview=true text 1.1 is not displayed. the divs are there so the template gets included, but the content is missing.
what's going on here?
I had similar problem today.
Viz. I had problem with visibility of any editable item in front end.
You need to clear your cache and that's it.

Breadcrumb menu in wordpress

I am stuck on how to create a breadcrumb menu in my wordpress so that when I select the main menu, the path shows its first inner menu. For example I have a main menu About us and Company Profile as its child. When I am select the About us, I want to get the Compony profile page and also the breadcrumb like About us / Company profile. Is there any way to do so? any plugins? I currently using Breadcrumb NavXT plugin for creating breadcrumb
You can add breadcrumb without using any plugin like this. Please add below code into your themes functions.php file.
function breadcrumbs($id = null){
?>
<div id="breadcrumbs">
Home</span> >
<?php if(!empty($id)): ?>
<a href="<?php echo get_permalink( $id ); ?>" ><?php echo get_the_title( $id ); ?></a> >
<?php endif; ?>
<span class="breadcrumb_last"><?php the_title(); ?></span>
</div>
<?php }
Now whenever you want to add breadcrumb just call this function like this.
<?php breadcrumbs(); ?>
As you mentioned above you have to add about page id into this function and call this to company profile page if this page is child page of about page than this works.
<?php breadcrumbs($id); ?>

Resources