I am working on flex slider module and I want to add one button in caption so for that I have added one field in content type with Machine name: field_image_url
and Field Type: text
.
Now I am changing in core file of the module to fetch that URL
into the front end.For that code is below:
<?php
/**
* @file
* Default output for a Flex Slider node.
*/
?>
<div class="flex-nav-container">
<div class="flexslider-content flexslider clearfix" id="flexslider-<?php print $id; ?>">
<ul class="slides">
<?php foreach($items as $item) : ?>
<li><?php print render($item); ?>
<?php if(!empty($item['#item']['title']) || !empty($item['#item']['alt'])) : ?>
<div class="flex-caption">
<h3><?php print $item['#item']['alt'];?></h3>
<p><?php print $item['#item']['title']; ?></p>
<?php if(isset($node->field_image_url)): ?>
<a href="<?php print render ($node->$field_image_url); ?>" class="btn btn-theme">Learn More</a>
<?php endif; ?>
</div>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
I know I am making some mistake as I am very new to drupal development.
<?php if(isset($node->field_image_url)): ?>
<a href="<?php print render ($node->$field_image_url); ?>" class="btn btn-theme">Learn More</a>
<?php endif; ?>
Above code is for fetching URL.It is not giving me any error, but it is also not showing me the button.I have already entered URL for one slide.
Where am I lacking ?
Edited :
I want to also mention that Slider
is on front page and there is an article content just below to the slider.
I have given node path to the front page from the Configuration to show it on front page.
So now, If I do
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
// Get the nid
$nid = arg(1);
// Load the node if you need to
$node = node_load($nid); print_r($node);
}
?>
It is giving me the node ID
of the article.I want the node ID
of the slider Image so that I can pull out the image URL field
that I have added to the Slider Image Content type.
EDITED:
<?php
//this code will load all nodes from your content type and then print them
$node_type = "slider_image";
$result = db_query("SELECT nid FROM node WHERE type = '%s' ", $node_type);
$nodes = array();
while ($obj = db_fetch_object ($result)) {
$node = node_load($obj->nid);
echo $node->field_image_url['und'][0]['value'];
echo '<br>';
$nodes[] = node_load($obj->nid);
}
?>
I have tried above code but it is giving me an error :
Recoverable fatal error: Argument 2 passed to db_query() must be of the type array, string given, called in path to modules\modules\flexslider\theme\flexslider-container.tpl.php on line 19 and defined in db_query() (line 2345 of path to site\includes\database\database.inc).
So to resolve above error, I tried following code with help of this
:
$result = db_query("SELECT nid FROM node WHERE type = ':type' ", array(':type' => $node_type));
But above code also gives me error : Fatal error: Call to undefined function db_fetch_object() in path to module\modules\flexslider\theme\flexslider-container.tpl.php on line 21