I need help module in joomla - joomla3.0

this is script of "tabs"module I want to change to select box with options
I tried to change the code but I could not this original code:
can someone help me?
<script type="text/javascript">
window.addEvent('load',function(){
var spTab<?php echo $uniqid ?> = new sptabs($('sptab<?php echo $uniqid ?>'), {
animation : <?php echo "'" . $animation . "'" ?>,
btnPos: <?php echo "'" . $btnPos . "'" ?>,
activator: <?php echo "'" . $activator . "'" ?>,
transition: <?php echo 'Fx.Transitions.' . $transition ?>,
fxduration: <?php echo $fxspeed ?>,
autoHeight : <?php echo $body_height ?>,
fixedHeight: <?php echo $fixed_height ?>
});
});
</script>
<div class="<?php echo $color ?>" id="sptab<?php echo $uniqid ?>">
<?php foreach ($list as $item) : ?>
<div style="display:none">
<div class="tab-padding">
<h2 style="display:none" class="title"><span id="<?php echo (preg_replace('/\s+/', '_',strtolower($item['title']))); ?>" class="sptab-title<?php echo ($item['sfx']) ? ' sptab_sfx' . $item['sfx'] : ''; ?>"><?php echo $item['title']; ?></span></h2>
<?php echo $item['content']; ?>
<div style="clear:both"></div>
</div>
</div>
<?php endforeach; ?>
</div>

I think you're looking for something like this:
<select>
<?php foreach ($list as $item) : ?>
<option><?php echo $item['title']; ?></option>
<?php endforeach; ?>
</select>
Note that you won't need the javascript you provided in your question

Related

How to add div after 3 rows in Joomla intro_items

I'm working on adding this to the com_content blog.php override.
Where we have the intro_items I need to have it count through 3 articles and then add a div where I can drop an ad script and than have it carry on and load the remaining 7 articles.
This is the intro_items loop. In parameters I have it set to 10 articles
<?php
$introcount = count($this->intro_items);
$counter = 0;
?>
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php $rowcount = ((int) $key % (int) $this->columns) + 1; ?>
<?php if ($rowcount === 1) : ?>
<?php $row = $counter / $this->columns; ?>
<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid clearfix">
<?php endif; ?>
<div class="span<?php echo round(12 / $this->columns); ?>">
<div class="item column-<?php echo $rowcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>"
itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<?php
$this->item = &$item;
echo $this->loadTemplate('item');
?>
</div>
<!-- end item -->
<?php $counter++; ?>
</div><!-- end span -->
<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
</div><!-- end row -->
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
I came up with the following, which works, but would like an opinion if there is a better way to do this.
<?php
$introcount = count($this->intro_items);
$counter = 0;
?>
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php $rowcount = ((int) $key % (int) $this->columns) + 1; ?>
<?php if ($rowcount === 1) : ?>
<?php $row = $counter / $this->columns; ?>
<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid clearfix">
<?php endif; ?>
<?php if ($row != 2) : ?>
<div class="span<?php echo round(12 / $this->columns); ?>">
<div class="item column-<?php echo $rowcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>"
itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<?php
$this->item = &$item;
echo $this->loadTemplate('item');
?>
</div>
<?php endif; ?>
<?php if ($row === 2) : ?>
<div class="span<?php echo round(12 / $this->columns); ?>">
<div class="item column-<?php echo $rowcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>"
itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<?php
$this->item = &$item;
echo $this->loadTemplate('item');
?>
<!-- mobile ad banner zone -->
<div class="cat-banner bannerzonepadding visible-phone">
<script type="text/javascript" language="javascript" src="http://myadsrc.demo"></script>
</div>
</div>
<?php endif; ?>
<!-- end item -->
<?php $counter++; ?>
</div><!-- end span -->
<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
</div><!-- end row -->
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
Would this approach work?
you add an ID to a wrapper around your list of intro_items
use jQuery and CSS nth-child selector to target the third child in the intro_items list
then use jQuery .after() function to insert the HTML for your ad
Pseudo code
$("#intro_items_wrapper .items-row:nth-child(3)").after('<!-- mobile ad code here -->');
Actual code
$("#intro_items_wrapper .items-row:nth-child(3)").after('<!-- mobile ad banner zone -->
<div class="cat-banner bannerzonepadding visible-phone">
<script type="text/javascript" language="javascript" src="http://myadsrc.demo"></script>
</div>');
Here's a working demo:
https://codepen.io/panchroma/pen/EEwaQX
Good luck!

Edit table-cells in a view

Yii Version 1.1.15
I have a model which contains a serialized array (table) in an attribut. Showing this array as a table in a view works fine.
But I want to update the table-cells and then again save the array serialized in the model. And this does not work. The output stops there (*) without errors.
Here you can see what I did:
$model->table contains a serialized array. The unserialized array looks like this:
array(
array('dog', 'cat', 'cow'),
array('meat', 'milk', 'gras'),
)
I unserialize the table in the controller:
controller: contactController.php
$model = Contact::model()->findByPk((int) $id);
$table = unserialize($model->input)
$this->render('contact_form', array(
'table' => $table));
}
And now I want to show and edit the array $table in a form as a html-table:
view: contact_form.php
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'contact-form',
));
?>
<table border="2">
<?php foreach ($table as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td>
<!-- (*) output stops here, without errors -->
<?= $form->textArea($value, '', array('rows' => 3, 'cols' => 20)); ?>
</td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
<div class="row buttons">
<?php echo CHtml::submitButton("save"); ?>
</div>
<?php $this->endWidget(); ?>
The output stops before "... textArea ...".
If I only show $table in a view (without a form) it works like a charme:
<table border="2">
<?php foreach ($table as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?= CHtml::encode($value) ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
Hope this helps to help me :-) How can I get this nice idea working?
Actually you are missing the arguments of CactiveForm.textArea(.......)
http://www.yiiframework.com/doc/api/1.1/CActiveForm#textArea-detail
textArea($value, '', array('rows' => 3, 'cols' => 20)); ?>
Instead of it your code should be
textArea($model, $value, array('rows' => 3, 'cols' => 20)); ?>

Sort from low to high using wordpress review widget

Need some help getting widget to sort the reviews from low to high. I know this is reverse of the norm, but this website focuses on how "bad" something is. The website is here: http://designtatics.fatcow.com/Badkickstarter/ it's the second tab down called top 3. Excuse the mess, still a work in progress.
// order by rating?
if (isset($order) && $order == 'rating') {
$query_args['orderby'] = 'meta_value';
}
else {
$query_args['orderby'] = 'date';
}
$r = new WP_Query($query_args);
I've already tried adding $query_args['order'] = 'ASC'; with no luck. This is all new to me so the more specific the better. Thanks!
UPDATE: I think I was trying to modify the wrong widget, heres the new code:
<?php
class Bunyad_TabbedRecent_Widget extends WP_Widget
{
public function __construct()
{
parent::__construct(
'bunyad-tabbed-recent-widget',
'Bunyad - Recent Tabs',
array('description' => __('Tabs: Recent, category1, category2...', 'bunyad-widgets'), 'classname' => 'tabbed')
);
add_action('save_post', array($this, 'flush_widget_cache'));
add_action('deleted_post', array($this, 'flush_widget_cache'));
add_action('switch_theme', array($this, 'flush_widget_cache'));
// init hook
add_action('init', array($this, 'init'));
}
public function init()
{
// only in admin cp for form
if (is_admin()) {
wp_enqueue_script('widget-tabs', plugins_url('/bunyad-widgets/js/widget-tabs.js'));
}
}
// #todo wrap existing widgets with in-memory cache
public function widget($args, $instance)
{
global $post; // setup_postdata not enough
// set defaults
$titles = $cats = $tax_tags = array();
extract($args);
extract($instance);
// missing data?
if (!count($titles) OR !count($cats)) {
_e('Recent tabs widget still need to be configured! Add tabs, add a title, and select type for each tab in widgets area.', 'bunyad-widgets');
return;
}
$tabs = array();
foreach ($titles as $key => $title) {
// defaults missing?
if (empty($tax_tags[$key])) {
$tax_tags[$key] = '';
}
if (empty($cats[$key])) {
$cats[$key] = '';
}
$tabs[$title] = array('cat_type' => $cats[$key], 'tag' => $tax_tags[$key]);
}
// latest posts
$posts = $this->get_posts($tabs, $number);
?>
<?php echo $before_widget; ?>
<ul class="tabs-list">
<?php
$count = 0;
foreach ($posts as $key => $val): $count++; $active = ($count == 1 ? 'active' : '');
?>
<li class="<?php echo $active;?>">
<?php echo $key; ?>
</li>
<?php endforeach; ?>
</ul>
<div class="tabs-data">
<?php
$i = 0;
foreach ($posts as $tab => $tab_posts): $i++; $active = ($i == 1 ? 'active' : ''); ?>
<ul class="tab-posts <?php echo $active; ?> posts-list" id="recent-tab-<?php echo esc_attr($i); ?>">
<?php if ($tabs[$tab] == 'comments'): ?>
<?php
foreach ($tab_posts as $comment):
?>
<li class="comment">
<span class="author"><?php printf('%s said', get_comment_author_link($comment->comment_ID)); ?></span>
<p class="text"><?php comment_excerpt($comment->comment_ID); ?></p>
<?php echo get_the_title($comment->comment_post_ID); ?>
</li>
<?php
endforeach;
?>
<?php else: ?>
<?php foreach ($tab_posts as $post): setup_postdata($post); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail('post-thumbnail', array('title' => strip_tags(get_the_title()))); ?>
<?php if (class_exists('Bunyad') && Bunyad::options()->review_show_widgets): ?>
<?php echo apply_filters('bunyad_review_main_snippet', ''); ?>
<?php endif; ?>
</a>
<div class="content">
<time datetime="<?php echo get_the_date('Y-m-d\TH:i:sP'); ?>"><?php echo get_the_date(); ?> </time>
<span class="comments"><a href="<?php echo esc_attr(get_comments_link()); ?>"><i class="fa fa-comments-o"></i>
<?php echo get_comments_number(); ?></a></span>
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>">
<?php if (get_the_title()) the_title(); else the_ID(); ?></a>
</div>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<?php endforeach; ?>
</div>
<?php echo $after_widget; ?>
<?php
wp_reset_postdata();
}
public function get_posts($tabs, $number)
{
// posts available in cache? - use instance id to suffix
$cache = get_transient('bunyad_tabbed_recent_posts');
if (is_array($cache) && isset($cache[$this->number])) {
return $cache[$this->number];
}
// get posts
$args = array('numberposts' => $number, 'ignore_sticky_posts' => 1);
foreach ($tabs as $key => $val) {
$opts = array();
switch ($val['cat_type']) {
case 'popular':
$opts['orderby'] = 'comment_count';
break;
case 'comments':
$posts[$key] = get_comments(array('number'=> $number, 'status' => 'approve'));
continue 2; // jump switch and foreach loop
case 'top-reviews':
// get top rated of all time
$opts = array_merge($opts, array('orderby' => 'meta_value', 'meta_key' => '_bunyad_review_overall'));
break;
case 'recent':
break;
case 'tag':
$opts['tag'] = $val['tag'];
break;
default:
$opts['cat'] = intval($val['cat_type']);
break;
}
//$query = new WP_Query(array_merge($args, $opts));
$posts[$key] = get_posts(array_merge($args, $opts));
}
if (!is_array($cache)) {
$cache = array();
}
$cache[ $this->number ] = $posts;
set_transient('bunyad_tabbed_recent_posts', $cache, 60*60*24*30); // 30 days transient cache
return $posts;
}
public function flush_widget_cache()
{
delete_transient('bunyad_tabbed_recent_posts');
}
public function update($new, $old)
{
// fix categories
foreach ($new['cats'] as $key => $cat) {
$new['cats'][$key] = strip_tags($cat);
}
foreach ($new['titles'] as $key => $title) {
$new['titles'][$key] = strip_tags($title);
}
foreach ($new['tax_tags'] as $key => $tag) {
$new['tax_tags'][$key] = trim(strip_tags($tag));
}
$new['number'] = intval($new['number']);
// delete cache
$this->flush_widget_cache();
return $new;
}
public function form($instance)
{
$instance = array_merge(array('titles' => array(), 'cats' => array(0), 'number' => 4, 'cat' => 0, 'tax_tags' => array()), $instance);
extract($instance);
?>
<style>
.widget-content p.separator { padding-top: 10px; border-top: 1px solid #d8d8d8; }
.widget-content .tax_tag { display: none; }
</style>
<div id="tab-options">
<script type="text/html" class="template-tab-options">
<p class="title separator">
<label><?php printf(__('Tab #%s Title:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label>
<input class="widefat" name="<?php
echo esc_attr($this->get_field_name('titles')); ?>[%n%]" type="text" value="%title%" />
</p>
<div class="cat">
<label><?php printf(__('Tab #%s Category:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label>
<?php
$r = array('orderby' => 'name', 'hierarchical' => 1, 'selected' => $cat, 'show_count' => 0);
// categories list
$cats_list = walk_category_dropdown_tree(get_terms('category', $r), 0, $r);
// custom options
$options = array(
'recent' => __('Recent Posts', 'bunyad-widgets'),
'popular' => __('Popular Posts', 'bunyad-widgets'),
'top-reviews' => __('Top Reviews', 'bunyad-widgets'),
'tag' => __('Use a Tag', 'bunyad-widgets'),
);
?>
<select name="<?php echo $this->get_field_name('cats') .'[%n%]'; ?>">
<?php foreach ($options as $key => $val): ?>
<option value="<?php echo esc_attr($key); ?>"<?php echo ($cat == $key ? ' selected' : ''); ?>><?php echo esc_html($val); ?></option>
<?php endforeach; ?>
<optgroup label="<?php _e('Category', 'bunyad-widgets'); ?>">
<?php echo $cats_list; ?>
</optgroup>
</select>
<div class="tax_tag">
<p><label><?php printf(__('Tab #%s Tag:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label> <input type="text" name="<?php
echo esc_attr($this->get_field_name('tax_tags')); ?>[%n%]" value="%tax_tag%" /></p>
</div>
<p>[x] <?php _e('remove', 'bunyad-widgets'); ?></p>
</div>
</script>
<p class="separator"><?php _e('Add More Tabs', 'bunyad-widgets'); ?></p>
<?php
if (is_integer($this->number)): // create for valid instances only
foreach ($cats as $n => $cat):
?>
<script>
jQuery(function($) {
$('.widget-liquid-right [id$="bunyad-tabbed-recent-widget-'+ <?php echo $this->number; ?> +'"] #add-more-tabs').trigger(
'click',
[{
'n': <?php echo ($n+1); ?>,
'title': '<?php echo esc_attr($titles[$n]); ?>',
'selected': '<?php echo esc_attr($cat); ?>',
'tax_tag': '<?php echo esc_attr($tax_tags[$n]); ?>'
}]);
});
</script>
<?php
endforeach;
endif;
?>
</div>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts in each tab:', 'bunyad-widgets'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" />
</p>
<?php
}
}

Foreach echo without empty variable values

I´d like to use foreach to echo all images-path, but when a variable is empty $bild_5 than shouldn't display any HTML code around.
My code:
<html>
<?php
// var
$url = "http://www.URL/assets/";
$bild_1 = $url . "bild-1.jpg";
$bild_2 = $url . "bild-2.jpg";
$bild_3 = $url . "bild-3.jpg";
$bild_4 = $url . "bild-4.jpg";
$bild_5 = "";
// array
$bilder = array ("$bild_1", "$bild_2", "$bild_3", "$bild_4", "$bild_5");
?>
<ul>
<!-- foreach / Template -->
<?php foreach($bilder as $bild) { ?>
<li><img src="<?php echo $bild; ?>"</li>
<?php } ?>
</ul>
</html>
HTML-OUTPUT
<html>
<ul>
<li><img src="http://www.URL/assets/bild-1.jpg"</li>
<li><img src="http://www.URL/assets/bild-2.jpg"</li>
<li><img src="http://www.URL/assets/bild-2.jpg"</li>
<li><img src="http://www.URL/assets/bild-4.jpg"</li>
<li><img src=""</li> // Don´t display this HTML code; ( $bild_5 = ""; )
</ul>
</html>
Thanks for your help
Ogni
You can use continue to skip
<?php foreach($bilder as $bild) { ?>
<?php if (empty($bild)) continue; ?>
<li><img src="<?php echo $bild; ?>"</li>
<?php } ?>
I would also recommend that you use the alternate syntax for control structures when you mix PHP and HTML. It's easier to read
<?php foreach($bilder as $bild) : ?>
<li><img src="<?php echo $bild; ?>"</li>
<?php endforeach; ?>
Reference - http://php.net/manual/en/control-structures.alternative-syntax.php
Either use continue; as stated above, or simply let array_filter($bilder); run before your foreach

Cakephp 2.1 - AjaxHelper

I am using latest(2.1.1)version of cakePhp.
I was trying to implement ajaxHlper(http://www.cakephp.4uk.pl/) . but stuck in between.
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#EmployeeAddForm").validate();
});
</script>
</head>
<div class="employees form">
<?php echo $this->Form->create('Employee');?>
<fieldset>
<legend><?php echo __('Add Employee'); ?></legend>
<?php
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
//echo $this->Form->input('age');
echo $this->Form->input('age', array('class' => 'required number'));
echo $this->Form->input('sex');
echo $this->Form->input('Adress.first_line');
echo $this->Form->input('Adress.second_line');
echo $this->Form->input('Adress.city');
echo $this->Form->input('Adress.state');
echo $ajax->autoComplete('Department.name', '/ajax/autoComplete')
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Employees'), array('action' => 'index'));?></li>
<li><?php echo $this->Html->link(__('List Adresses'), array('controller' => 'adresses', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Adress'), array('controller' => 'adresses', 'action' => 'add')); ?> </li>
</ul>
This is my add.ctp file where Department.name I am trying to autocomplete using ajaxHelper.
In my EmployeesController.php I have autocomplete function which is like
function autoComplete() {
echo $this->params['url']['q'] . "---";
$this->loadModel("Department");
$this->set('departments', $this->Department->find('all', array(
'conditions' => array(
'Department.name LIKE ' => '%'.$this->params['url']['q'].'%'
),
'limit' => $this->params['url']['limit'],
'fields' => array('name')
)));
$this->layout = 'ajax';
}
It's not working. What could be the mistake I am doing?
it gives me following error:
Notice (8): Undefined variable: ajax [APP\View\Employees\add.ctp, line 84]
Fatal error: Call to a member function autoComplete() on a non-object in C:\xampplite\htdocs\cakephp\app\View\Employees\add.ctp on line 84
Assuming you have added the helper to the $helpers array of your controller, you have to access the helper with $this->Ajax->autoComplete() instead of $ajax->autoComplete().

Resources