Drupal 7 render an array in Block_view - arrays

I want to render an array and print the output as Block[content]. There is either my Foreach or the way I use $item array or $row that is wrong. I will appreciate your help.
function produkt_block_view($delta = '')
{
$block = array();
$list = produkt_produkliste(1);
$items = array();
foreach ($list as $row) {
$items[1] = $row->uri;
$items[2] = $row->title;
$items[3] = $row->body_value;
}
switch($delta) {
case 'produkt' :
$block['content'] = '<a href="/19">';
$block['content'] .= '<img class="pimg" src="'.$row->uri.'" alt="Se alle vores filter elementer her">';
$block['content'] .= '<p class="pname">"'.$row->title.'"</p>';
$block['content'] .= '<p>"'.$row->body_value.'"</p>';
$block['content'] .= theme ('item_list',array('items' => $items, 'type' => 'ol', 'attribute' => 'produkt'));
break;
}
return $block;
}

Related

how to show as row_number() in codeignitier

need help what wrong with my code where this my sql command where successfull run in mysql :
SELECT func_inc_var_session() As row_number ,
vruasjalan2.*
FROM vruasjalan2 Where skid = #skid
ORDER BY kategoriruasjalanid, subkategoriruasjalanid,ruasjalanid;"
but when i want to display in my controller row_number start error say"Call to undefined method Jalan_model::num_rows()"
public function ajax_list()
{
$list = $this->Jalan->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $Jalan) {
$no++;
$row = array();
$row[] = $no;
$row[] = $Jalan->row_number;
$row[] = $Jalan->ruasjalanid;
$row[] = $Jalan->skid;
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->Jalan->count_all(),
"recordsFiltered" => $this->Jalan->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
}
and this is my model
public function get_list_companys()
{
$this->db->select('vruasjalan2.*');
$this->db->from($this->table);
$this->db->order_by('kategoriruasjalanid','asc');
$query = $this->db->get();
$result = $query->result();
$companys = array();
foreach ($result as $row)
{
$companys[] = $row->kategoriruasjalanid;
}
return $companys;
}
if there any expert know this problems

Sitemap custom module

I am writing a custom module for site map in drupal 7. What I had done is below.
function escorts_sitemap_render_menu ($menu)
{
$output = "<ul>";
foreach ($menu as $item)
{
$link = $item["link"];
if ($link["hidden"])
{
continue;
}
$output .= "<li>" . $link["title"] . "</li>";
if ($item["below"])
{
$output .= sitemap_render_menu($item["below"]);
}
}
$output .= "</ul>";
return $output;
}
function escorts_sitemap_content ()
{
$output = "<h1>Escorts Sitemap</h1>";
$output .= "<ul class=\"site_map_list\">";
$output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
return $output;
}
function escorts_sitemap_menu ()
{
$items = array();
$items["sitemap"] = array (
"title" => "Escorts Sitemap",
"page callback" => "escorts_sitemap_content",
"access arguments" => array("access content"),
"type" => MENU_CALLBACK);
return $items;
}
then in template.php I implemented hook_theme too, below is the code :
function escorts_theme() {
return array(
'escorts_sitemap_content' => array(
'render element' => 'content',
'template' => 'page--sitemap',
'path' => drupal_get_path('theme', 'escorts') . '/templates'
),
);
}
But it is not appearing as I have my custom template file page--sitemap.tpl.php, can any one please guide me. But now what should I write in page--sitemap.tpl.php in order to render my sitemap
Maybe You should try next:
function escorts_theme() {
return array(
'escorts_sitemap_content' => array(
'variables' => array('content' => NULL)
/**
* I would not call template like this, cause it looks like
* pattern page--[node-type]
*/
'template' => 'page--sitemap',
)
);
}
And inside of menu callback function
function escorts_sitemap_content () {
$output = "<h1>Escorts Sitemap</h1>";
$output .= "<ul class=\"site_map_list\">";
$output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
return theme('escorts_sitemap_content', $output);
}
This is one of ways. Also look in preprocess functions, and Drupal theme layer at all. And maybe ready module XML sitemap will be useful. Also be careful, if file is really located there.
And in template file just paste
<?php print $content; ?>
Regards

One character only is being returned when using foreach phpfox

I am trying to get some data from a table but when i use foreach it returns only 1 character or the 1st letter/number and one row is returned.
Here is my code.
home.class.php
public function getData()
{
$aRow = $this->database()->select('*')
->from('tablename')
->execute('getSlaveRow');
return $aRow;
}
ajax.class.php
public function getArr()
{
$data = 'No data found';
$results = Phpfox::getService('files.home')->getData();
if($results) {
$data = '<div id="fileparse" style="height:295px;overflow:auto;display:none;"</div>';
$data .= '<div id="filelist" style="height:295px;overflow:auto;">';
$data .= '<table style="width:100%;"><tr><td><b>File Name</b></td><td> <b>Account Type</b></td><td><b>Account Number</b></td><td><b>Company</b></td><td><b>Results</b></td></tr>';
foreach($results as $result) {
$data .= '<tr>';
$data .= '<td>'.$result['file'].'</td>';
$data .= '<td>'.$result['result'].'</td>';
$data .= '</tr>';
}
$data .= '</table>';
$data .= '</div>';
} else
$data = 'No results found';
$this->html('#eqblock', $data);
}
use getSlaveRows insted of getSlaveRow
getSlaveRow return single array while getSlaveRows return all rows

How to add a class to entityform inputs

I have an entityform block and I want to add bootstrap classes to its input!
How can I do this and what files should I edit?
I'm using latest version of entityform and entity block on drupal.org
thank you
You need to add these functions to your template.php file inside your theme folder (replace THEME_NAME with the actual name of your theme):
function THEME_NAME_textfield($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'text';
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
_form_set_class($element, array('form-text'));
$element['#attributes']['class'][] = 'form-control';
$extra = '';
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = "<div class='input-wrapper'>";
$output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
$output .= "</div>";
return $output . $extra;
}
function THEME_NAME_button($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'submit';
element_set_attributes($element, array('id', 'name', 'value'));
$element['#attributes']['class'][] = 'form-' . $element['#button_type'];
$element['#attributes']['class'][] = 'btn btn-default';
if (!empty($element['#attributes']['disabled'])) {
$element['#attributes']['class'][] = 'form-button-disabled';
}
$value = $element['#attributes']["value"];
if( isset($element['#attributes']["button-type"]) && $element['#attributes']["button-type"] == "search" ) {
$value = $element['#attributes']["icon"];
unset($element['#attributes']["icon"]);
}
return '<button' . drupal_attributes($element['#attributes']) . '>' . $value . '</button>';
}
function THEME_NAME_select($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'size'));
_form_set_class($element, array('form-select', 'form-control'));
return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
}
These functions will add the classes you need for the button, textfield and select input types. Also you will need to include the bootstrap files in your theme.

wordpress custom post show some post in a div and rest posts in some different div

In wordpress I have made a custom post type. So for custom post type my code looks like this
add_action( 'init', 'broker_post_type' );
function broker_post_type() {
register_post_type( 'new_broker',
array(
'labels' => array(
'name' => __( 'Brands' ),
'singular_name' => __( 'Brand' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
)
);
}
To show the contents of custom posts through shortcode I have done like this
function display_broker_posts() {
$args = array(
'post_type' => 'new_broker',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
);
$dee_bios = new WP_Query( $args );
if( $dee_bios->have_posts() ):
$dee_output = '<div id="brokers-wrap">';
$dee_output .= '<div id="brokers-bg-wrap">';
$dee_output .= '<div class="brokers-content">';
$dee_output .= '<div class="brokers-left-content">';
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) {
$dee_output .= '<a class="branding first" href=""><div class="one-half first">';
}
else {
$dee_output .= '<a href="" class="branding"><div class="one-half">';
}
$dee_output .= get_the_post_thumbnail( $dee_bios->post->ID,'small', 'bios', array( 'class' => 'alignleft' ) );
$dee_output .= '<span></span>';
// $dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>';
$dee_output .= '</div><!--end .one-half-->';
endwhile;
$dee_output .= '<div class="clear"></div><!--clear all floats-->';
$dee_output .= '</div><!-- end #bios-->';
endif;
wp_reset_postdata();
return $dee_output;
}
add_shortcode( 'display_brokers', 'display_broker_posts' );
Here its working fine. I can see the featured image in my page by using shortcode. But lets say I have 20 custom posts and I want that the first 6 will show in a different div and another 14 in another div. So can someone kindly tell me how to do this? Any help will be really appreciable. Thanks
How about something like this:
$dee_bios = new WP_Query( $args );
$i = 0;
if( $dee_bios->have_posts() ):
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if ($i ==0) {
$dee_output .= '<div id="first_broker_div">';
} elseif ($i == 6) {
$dee_output .= '</div><div id="second_broker_div">';
}
$dee_output .= //Your post content
$i++;
endwhile;
$dee_output .= '</div>';
endif;

Resources