How to display all images fields on custom page with post type - image

I'm trying to loop through the fields of ACF to display all the images of a post type and a specific category
I give a practical example:
I have an ACF image field (image_of_project) and I want to view all the images uploaded in a post type (projects) associated with XYZ category
Now I created this loop:
'
$loop = new WP_Query( array(
'post_type' => 'projects',
'posts_per_page' => 9,
) );
while ( $loop->have_posts() ) : $loop->the_post();
$images = get_field('image_of_project');
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<div class="item">
<a href="<?php echo get_permalink( $post->ID ); ?>" target="_blank">
<?php echo wp_get_attachment_image( $image ); ?>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
'
The images are displayed but I do not understand why it duplicates me every single image and does not show me only the images of linked to a specific category.
Thanks to anyone who will help me on this mission!

For those interested in the feature, here’s how it worked for me.
function.php
// Loop Gallery Cat1
function my_custom_gallery_cat1() {
query_posts(array(
'post_type' => 'gd_project',
'orderby' => 'rand',
'posts_per_page' => 10,
'tax_query' => array(
array (
'taxonomy' => 'gd_projectcategory',
'field' => 'slug',
'terms' => 'example-terms',
)
),
));
?> <div class="masonry">
<?php
while (have_posts()) : the_post();
$image_field = get_field('image');
$image_url = $image_field['url'];
$image_alt = $image_field['alt']; ?>
<div class="grid-item">
<a href="<?php echo get_permalink( $post->ID ); ?>" target="_blank">
<img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>" />
<h4><?php the_field( 'title' ); ?></h4>
</a>
</div>
<?php endwhile; ?>
</div> <?php
}
add_shortcode('example-terms', 'my_custom_gallery_cat1');
single-example.php
<div class="container-fluid">
<div class="row">
<?php echo do_shortcode('[categoria]');?>
</div>
</div>

Related

How add create AdditionalActionBlockHtml into massactions in category products grid in magento?

How add create AdditionalActionBlockHtml into massactions in category products grid?
like this status
I founded getAdditionalActionBlockHtml in app/design/adminhtml/default/default/template/widget/grid/massaction.phtml
But I'm dont understand how it's work.
<div class="right">
<div class="entry-edit">
<?php if ($this->getHideFormElement() !== true):?>
<form action="" id="<?php echo $this->getHtmlId() ?>-form" method="post">
<?php endif ?>
<?php echo $this->getBlockHtml('formkey')?>
<fieldset>
<span class="field-row">
<label><?php echo $this->__('Actions') ?></label>
<select id="<?php echo $this->getHtmlId() ?>-select" class="required-entry select absolute-advice local-validation">
<option value=""></option>
<?php foreach($this->getItems() as $_item): ?>
<option value="<?php echo $_item->getId() ?>"<?php echo ($_item->getSelected() ? ' selected="selected"' : '')?>><?php echo $_item->getLabel() ?></option>
<?php endforeach; ?>
</select>
</span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-hiddens"></span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-additional"></span>
<span class="field-row">
<?php echo $this->getApplyButtonHtml() ?>
</span>
</fieldset>
<?php if ($this->getHideFormElement() !== true):?>
</form>
<?php endif ?>
</div>
<div class="no-display">
<?php foreach($this->getItems() as $_item): ?>
<div id="<?php echo $this->getHtmlId() ?>-item-<?php echo $_item->getId() ?>-block">
<?php echo $_item->getAdditionalActionBlockHtml() ?>
</div>
<?php endforeach; ?>
</div>
</div>
I decided this via add methods in massactions
public function addMassAction($observer)
{
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'catalog_product')
{
$stores = Mage::getSingleton('adminhtml/system_config_source_store')->toOptionArray();
$block->addItem('export', array(
'label' => Mage::helper("prodestransl")->__("Export"),
'url' => Mage::helper('adminhtml')->getUrl('prod/adminhtml_export/run'),
'additional' => array(
'stores' => array(
'name' => 'stores',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Stores'),
'values' => $stores
)
)
));
}
}

Dependent dropdown for department and course

I a working on a dependent dropdown in yii, I want the department dropdown to autoload with the departments depending on what faculty I select, the course dropdown to load with courses once i select a department, the code almost works except that the dropdowns are updating themselves rather than the dropdowns beneath. How can I make them update properly?
this is the
views/site/newuser:
`<div class="row">`
<?php echo $form->labelEx($model,'faculty_id'); ?>
<?php echo $form->dropDownList($model,'faculty_id',
CHtml::listData(Faculty::model()->findAll(),'id','faculty_name'),
array(
'prompt'=>'Select Faculty',
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('site/loaddepartment'),
'update'=>'#NewUser_faculty_id',
'data'=>array('faculty_id'=>'js:this.value'),)));
?>
<?php echo $form->error($model,'faculty_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'department_id'); ?>
<?php echo $form->dropDownList($model,'department_id',
CHtml::listData(Department::model()->findAll(),'id','department_name'),
array(
'prompt'=>'Select Department',
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('site/loadcourses'),
'update'=>'#NewUser_department_id',
'data'=>array('department_id'=>'js:this.value'),)));
?>
<?php echo $form->error($model,'department_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'course_id'); ?>
<?php echo CHtml::dropDownList('department_name','', array(), array(
'prompt'=>'Select Course'
)); ?>
<?php echo $form->error($model,'course_id'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
this is in the controller:
public function actionloaddepartment()
{
$data=Department::model()->findAll('faculty_id=:faculty_id',
array(':faculty_id'=>(int) $_POST['faculty_id']));
$data=CHtml::listData($data,'id','department_name');
echo "<option value=''>Select Department</option>";
foreach($data as $value=>$department_name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($department_name),true);
}
public function actionloadcourses()
{
$data=Courses::model()->findAll('department_id=:department_id',
array(':department_id'=>(int) $_POST['department_id']));
$data=CHtml::listData($data,'id','course_name');
echo "<option value=''>Select course</option>";
foreach($data as $value=>$course_name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($course_name),true);
}
so, I was able to get a fix, Thank God, here it is, so incase any one might need it
this is the new/views/site/newuser:
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'first_name'); ?>
<?php echo $form->textField($model,'first_name'); ?>
<?php echo $form->error($model,'first_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'last_name'); ?>
<?php echo $form->textField($model,'last_name'); ?>
<?php echo $form->error($model,'last_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'faculty_id'); ?>
<?php echo $form->dropDownList($model,'faculty_id',
CHtml::listData(Faculty::model()->findAll(),'id','faculty_name'),
array(
'prompt'=>'Select Faculty',
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('site/loaddepartment'),
'update'=>'#department_id',
'data'=>array('faculty_id'=>'js:this.value'
),
)));
?>
<?php echo $form->error($model,'faculty_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'department_id'); ?>
<?php echo CHtml::dropDownList('department_id','', array(),
array(
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('site/loadcourses'),
'update'=>'#course_id',
'data'=>array('department_id'=>'js:this.value'
),
)))
?>
<?php echo $form->error($model,'department_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'course_id'); ?>
<?php echo CHtml::dropDownList('course_id','', array()
)?>
<?php echo $form->error($model,'course_id'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
This is the New controller:
public function actionloaddepartment()
{
$data=Department::model()->findAll('faculty_id=:faculty_id',
array(':faculty_id'=>(int) $_POST['faculty_id']));
$data=CHtml::listData($data,'id','department_name');
foreach($data as $value=>$department_name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($department_name),true);
}
public function actionloadcourses()
{
$data=Courses::model()->findAll('department_id=:department_id',
array(':department_id'=>(int) $_POST['department_id']));
$data=CHtml::listData($data,'id','course_name');
foreach($data as $value=>$course_name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($course_name),true);
}

getChildrenCategories not working in magento, sort category by position in admin

i won't to sort categories in frontend as in admin if i use getChildren then it will not sort categories as in admin but if i use getChildrenCategories then no result
<?php
$cats = Mage::getModel('catalog/category')->load(74)->getChildren();
$catIds = explode(',',$cats);
$categories = array();
foreach($catIds as $catId) {
$category = Mage::getModel('catalog/category')->load($catId);
$categories[$category->getName()] = array(
'url' => $category->getUrl(),
'img' => $category->getImageUrl()
);
}
ksort($categories, SORT_STRING);
?>
<ul>
<?php foreach($categories as $name => $data): ?>
<li>
<a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
<img class="cat-image" src="<?php echo $data['img']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
Use an ordered collection. See below example:
<?php
$category = Mage::getModel('catalog/category')->load(74);
$collection = $category->getCollection();
->addAttributeToSelect('name')
->addAttributeToSelect('image')
->addIdFilter($category->getChildren())
->setOrder('name', Varien_Db_Select::SQL_DESC);
You can then loop through the collection to render the items.

ajax calling another ajax in yii

I can access the registration form which appears in a model window via ajax on any page as coded in the menu layout .
I need some thing on click of submit button of registration form it should get display a thank you message which is also via ajaxin the same div as that of wherein the registration form appears
registratiincontrooler
if ($model->save()) {echo "thank you for registration";return; }
registration view
<?php
/* #var $this UserProfileController */
/* #var $model UserProfile */
$this->breadcrumbs=array(
'User Profiles'=>array('index'),
'Create',
);
?>
<div id="ajax101" >
<div class="form" >
<?php $form=$this->beginWidget('UActiveForm', array(
'id'=>'registration-form',
'enableAjaxValidation'=>true,
'disableAjaxValidationAttributes'=>array('RegistrationForm_verifyCode'),
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
'htmlOptions' => array('enctype'=>'multipart/form-data'),
)); ?>
<p class="note"><?php echo UserModule::t('Fields with <span class="required">*</span> are required.'); ?></p>
<?php echo $form->errorSummary(array($model/*,$profile*/)); ?>
<div class="row">
<div class="rlabel">
<?php echo $form->labelEx($model,'username', array("style"=>"display:inline")); ?>
</div>
<div class="rtextfield">
<?php echo $form->textField($model,'username', array("style"=>"margin-left:43px")); ?>
</div>
<div class="rerror">
<?php echo $form->error($model,'username', array("style"=>"margin-left:113px")); ?>
</div>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password', array("style"=>"display:inline")); ?>
<?php echo $form->passwordField($model,'password', array("style"=>"margin-left:43px")); ?>
<?php echo $form->error($model,'password', array("style"=>"margin-left:113px")); ?>
<p class="hint">
<?php echo UserModule::t("Minimal password length 4 symbols."); ?>
</p>
</div>
<div class="row">
<?php echo $form->labelEx($model,'verifyPassword', array("style"=>"display:inline")); ?>
<?php echo $form->passwordField($model,'verifyPassword'); ?>
<?php echo $form->error($model,'verifyPassword', array("style"=>"margin-left:113px")); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email', array("style"=>"display:inline")); ?>
<?php echo $form->textField($model,'email', array("style"=>"margin-left:65px")); ?>
<?php echo $form->error($model,'email', array("style"=>"margin-left:113px")); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'user_type', array("style"=>"display:inline")); ?>
<?php echo $form->dropDownList($model,'user_type',$model->getUType()); ?>
<?php echo $form->error($model,'user_type', array("style"=>"margin-left:113px")); ?>
</div>
<?php if (UserModule::doCaptcha('registration')): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
<?php echo $form->error($model,'verifyCode'); ?>
<p class="hint"><?php echo UserModule::t("Please enter the letters as they are shown in the image above."); ?>
<br/><?php echo UserModule::t("Letters are not case-sensitive."); ?></p>
</div>
<?php endif; ?>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'#ajax101')); ?>//div for form
</div>
<?php $this->endWidget(); ?>
</div>
</div><!-- form -->
<?php endif; ?>
I think the problem exists here
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'form')); ?>//div for form
</div>
example if I have 3 menu items
home
aboutus
contact
suppose visited home when I click on register a model window with registration form appears and when i click on submit button model->save as well make another call using ajax to update that model window with thank you message
similarly with other items in menu
whats happening is it saves and redirects to /user/registration with thank you but i need same model window and not to be updated with thank message and not redirected thank message
I did try this but it did not save
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),'',array('update'=>'form-content')); ?>
I am calling ajax within ajax .
try with
<?php
echo CHtml::ajaxSubmitButton(signup , CHtml::normalizeUrl(array('<controller>/<action>', 'render' => true)), array(
'dataType' => 'json',
'type' => 'post',
'success' => 'function(data) {
}',
'beforeSend' => 'function(){
}','complete' => 'function(){
}',
), array('id' => 'signup', 'class' => ''));
?>
The problem is in your controller, you have to stop Yii, return; alone won't cut it.
if ($model->save()) {
if($this->isAjaxRequest)
{
ehco 'thank you for registration';
Yii::app()->end(); // to stop yii
}
else
{
// probably redirect
}
}

Warning: Invalid argument supplied for for each () in Wordpress

Please Help!! Getting an following Error.
It says something is wrong in 'taxonomy-coupon-store.php, but couldn't find anything wrong?
Warning: Invalid argument supplied for foreach() in /home/searche1/public_html/wp-content/themes/Deals/taxonomy-coupon_store.php
Here is my taxonomy-coupon-store-php file:
ID, 'coupon_store' );
foreach ( $store_obj as $element ) {
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
?>
<header class="page-heading clearfix">
<div class="entry-thumb-wrapper">
<img src="<?php echo $store_image_preview; ?>" class="store-thumbnail" alt="<?php the_title(); ?>" />
</div><!-- .entry-thumb-wrapper -->
<div class="entry-excerpt">
<h1 class="entry-title"><?php echo $store_name; ?></h1>
<p class="store-url"><?php echo $store_url; ?></p>
<p class="store-desc"><?php echo $store_description; ?></p>
</div><!-- .entry-excerpt -->
</header><!-- .page-heading -->
<div class="content-heading clearfix">
<h3><?php _e('Active Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
if ( have_posts() ) :
while(have_posts()) : the_post();
get_template_part( 'content');
endwhile;
else :
get_template_part( 'coupon','none');
endif;
wp_reset_query();
?>
<?php
junkie_pagination();
?>
<div class="content-heading clearfix">
<h3><?php _e('Unreliable Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
$args=array(
'post_type'=>'coupon',
'posts_per_page' => 5,
'post_status' => 'expire',
'orderby' => 'DESC',
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => current_time('mysql'),
'compare' => '<',
'type' => 'DATE'
)
),
'tax_query' => array(
array(
'taxonomy' => 'coupon_store',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$recent = new WP_Query($args);
if ( $recent->have_posts() ) :
while($recent->have_posts()) : $recent->the_post();
get_template_part( 'content');
endwhile;
wp_reset_query();
else :
get_template_part( 'coupon', 'none' );
endif;
?>
</div><!-- #content -->
Please help!
<?php get_header(); ?>
<div id="content" class="content-loop" role="main">
<?php
$taxonomy='coupon_store';
$term = get_queried_object();
//get my store.
$store_obj = get_the_terms( $post->ID, 'coupon_store' );
foreach ( $store_obj as $element ) {
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
?>
<header class="page-heading clearfix">
<div class="entry-thumb-wrapper">
<img src="<?php echo $store_image_preview; ?>" class="store-thumbnail" alt="<?php the_title(); ?>" />
</div><!-- .entry-thumb-wrapper -->
<div class="entry-excerpt">
<h1 class="entry-title"><?php echo $store_name; ?></h1>
<p class="store-url"><?php echo $store_url; ?></p>
<p class="store-desc"><?php echo $store_description; ?></p>
</div><!-- .entry-excerpt -->
</header><!-- .page-heading -->
<div class="content-heading clearfix">
<h3><?php _e('Active Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
if ( have_posts() ) :
while(have_posts()) : the_post();
get_template_part( 'content');
endwhile;
else :
get_template_part( 'coupon','none');
endif;
wp_reset_query();
?>
<?php
junkie_pagination();
?>
<div class="content-heading clearfix">
<h3><?php _e('Unreliable Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
$args=array(
'post_type'=>'coupon',
'posts_per_page' => 5,
'post_status' => 'expire',
'orderby' => 'DESC',
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => current_time('mysql'),
'compare' => '<',
'type' => 'DATE'
)
),
'tax_query' => array(
array(
'taxonomy' => 'coupon_store',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$recent = new WP_Query($args);
if ( $recent->have_posts() ) :
while($recent->have_posts()) : $recent->the_post();
get_template_part( 'content');
endwhile;
wp_reset_query();
else :
get_template_part( 'coupon', 'none' );
endif;
?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Resources