I am trying to make image as a link in Codeigniter but <a> tag is not working. I am trying to make image as a link but inside foreach loop <a> tag is not working.
Here is my code
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<a href=<?php echo site_url($post->url)?>> <img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
</div>
</div>
change your code to this and please check again.
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<a href="<?php echo site_url($post->url)?>" style="display: block;">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
You can use
<?php echo anchor('your Controller_name/link','<img src="your path" /> ','class="btn btn-default btn-flat"')?>
instead of anchor Tag
Related
Very new Wordpress apprentice here. Trying to get my archive page to display posts in two columns going like:
Post 1 Post 2
Post 3 Post 4
Here is an example from a figma we were working on: https://ibb.co/N3XwtwD
My question is, what code can I add to my files to allow this? I currently have some bootstrap classes on the html portion I inserted here and it is displaying as one column, so I don't know if those classes will interfere with anything. Here is my archive.php code below:
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
while(have_posts()) {
the_post(); ?>
<div class="row">
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<img class="img-fluid mb-3"<?php
the_post_thumbnail();
?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
</div>
<?php }
echo paginate_links();
?>
</div>
<?php
get_footer();
?>
First time posting here so apologies if I left anything important out. Really appreciate this place!
Thanks!
You need to create a row every two posts and you have to add <div class="col-lg-6"> two times in a row. check below code.
<?php get_header(); ?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$count = 1;
while( have_posts() ) { the_post();
if ( $count % 2 == 1){ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php the_post_thumbnail(); ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php if ( $count % 2 == 0 ){ ?>
</div>
<?php } $count++; ?>
<?php }
if ( $count % 2 != 1 ) echo "</div>";
echo paginate_links(); ?>
</div>
Please replace with the below code that helps you.
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$counterval = 0;
while(have_posts()) {
the_post();
$counterval++;
if($counterval % 2 != 0)
{ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
if(!empty($featured_img_url)){ ?>
<img class="img-fluid mb-3" src="<?php echo esc_url($featured_img_url); ?>" />
<?php } ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php
if($counterval % 2 == 0)
{ ?>
</div>
<?php } ?>
<?php } ?>
<?php echo paginate_links();
?>
</div>
<?php
get_footer();
?>
I'd like to include an IF statement into my highlights.phtml file where I can check if my custom attribute (named preorder) has been selected or not. As the name indicates, this custom attribute can be set on a product to signify if it can be pre-ordered. How can I access this variable/attribute in the highlights slider code, below? It doesn't seem to be part of the $products array?
<?php $products = $this->getHighlightedProducts() ?>
<?php if (is_array($products) && count($products)): ?>
<div class="block block-related">
<div class="block-title">
<h2><?php echo $this->__('Highlighted Products') ?></h2>
</div>
<div class="block-content">
<div class="product-carousel">
<div class="product-carousel">
<ul class="highlighted-products-slider slider">
<?php $limit = 6; ?>
<?php foreach ($products as $product): ?>
<li class="item">
<div class="product" >
<a class="product-image" href="<?php echo $this->escapeHtml($product['url']) ?>">
<img src="<?php echo $this->escapeHtml($product['image']) ?>">
</a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($product['name']) ?>
</p>
<?php echo $product['price'] ?>
</div>
<div class="actions">
<a href="<?php echo $this->escapeHtml($product['add_to_cart_url']) ?>">
<button class="button btn-cart"><?php echo $this->__('Add to Cart') ?></button>
</a>
</div>
</div>
</li>
<?php
if(++$ct >= $limit)
break;
?>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
</div>
</div>
</div>
Get the attribute with the code i added, then use it for your logic. What you want to do with the attribute, you can do now. But $product['id'] has to exist!
You need the product id for this to work, else maybe the SKU.
Hope to help.
<?php $products = $this->getHighlightedProducts() ?>
<?php if (is_array($products) && count($products)): ?>
<div class="block block-related">
<div class="block-title">
<h2><?php echo $this->__('Highlighted Products') ?></h2>
</div>
<div class="block-content">
<div class="product-carousel">
<div class="product-carousel">
<ul class="highlighted-products-slider slider">
<?php $limit = 6; ?>
<?php foreach ($products as $product): ?>
<?php
$productToCheck= Mage::getModel('catalog/product')->load($product['id']);
//use this variable
$variable = $productToCheck->getData('preorder');
//use this variable when attribute is a dropdown
$variableIfItsADropdown = $product->getAttributeText('preorder');
?>
<li class="item">
<div class="product" >
<a class="product-image" href="<?php echo $this->escapeHtml($product['url']) ?>">
<img src="<?php echo $this->escapeHtml($product['image']) ?>">
</a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($product['name']) ?>
</p>
<?php echo $product['price'] ?>
</div>
<div class="actions">
<a href="<?php echo $this->escapeHtml($product['add_to_cart_url']) ?>">
<button class="button btn-cart"><?php echo $this->__('Add to Cart') ?></button>
</a>
</div>
</div>
</li>
<?php
if(++$ct >= $limit)
break;
?>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
</div>
</div>
</div>
In codeigniter currently I am working on shopping cart but the problem is I am not able to call a function using form_open in codeigniter.
However, in the same project in another place same code is working properly but in other view form_open it's not working.
Here is my code:
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',['class'=>'form-horizontal']);?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',['class'=>'btn btn-primary'])?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
<?php echo form_close(); ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>
check to see if you are loading the helper.
$this->load->helper('form');
somewhere in your code. preferably in the constructor.
also make sure that error notifications are are turned on, these sorts of problems should give errors that help.
change your code with below one
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',array('class'=>'form-horizontal'));?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',array('class'=>'btn btn-primary'))?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
</div>
</div>
<?php echo form_close(); ?>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>
I am trying to use repeater inside repeater field. Could you please point me to where is the mistake?
<?php if(get_field('help_blocks')): ?>
<?php while(has_sub_field('help_blocks')): ?>
<div class="col-sm-4">
<div class="block">
<h5><?php the_sub_field('block_title'); ?></h5>
<?php the_sub_field('block_paragraph'); ?>
<?php if(get_field('block_list')): ?>
<ul class="list-style">
<?php while(has_sub_field('block_list')): ?>
<li><?php the_sub_field('list_item'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<img src="<?php the_sub_field('block_image'); ?>" alt="" />
<div class="text-center">
<a class="btn btn-primary" href="<?php the_sub_field('block_button_link'); ?>"><?php the_sub_field('block_button'); ?></a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
It looks like you're almost there.
You have this line:
<?php if(get_field('block_list')): ?>
It should be:
<?php if(get_sub_field('block_list')): ?>
Your nested repeater is a sub field of your repeater, so you need to use get_sub_field.
This is my WordPress loop code... :)
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php if (is_category('instagram')) {?>
<?php
$__width = '225';
$__height = '225';
?>
<div id="instagram-photos">
<a href="<?php the_permalink() ?>"class="instagram-photo">
<div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?> </div>
</a>
</div>
<?php }elseif(is_category('runway')) { ?>
<?php
$__width = '298';
$__height = '500';
?>
<div id="runway-category">
<a href="<?php the_permalink() ?>" class="runway-category-posts">
<div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?><div class="runway-title"><?php the_title(); ?></div></div>
</a>
</div>
<?php } elseif(is_category('')){?>
<article <?php post_class(); ?>>
<div class="latest-posts">
<div class="latest-posts-info">
<div class="title"><h1><?php the_title(); ?><h1></div>
<div class="text">
<?php the_excerpt(); ?>
</div>
<div class="post-share">
<div class="facebook-like" style="float:left;">
<img src="<?php echo get_template_directory_uri(); ?>/images/facebook-icon.png" />
</div>
<div class="twitter-follow" style="float:left;">
<a href="http://twitter.com/share?text=<?php the_title(); ?>&url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/twitter-icon.png" /></a>
</div>
<div class="google-share">
<a href="https://plus.google.com/share?url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/google-icon.png" /></a>
</div>
</div>
<div class="clear"></div><div class="post-read-more">Read More</div>
<div class="clear"></div>
</div>
<div class="latest-posts-img">
<?php //echo get_the_post_thumbnail(); ?>
<?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?>
</div>
<div class="clear"></div>
</div>
</article>
<?php }?>
<?php endwhile; else: ?>
<div class="content">
<p class="not-found-p">No articles found!</p>
</div>
<?php endif; ?>
As you see I have few conditions as is_category('instagram').
The thing is: I need to limit the post quantity in exact category, not at all them.
How can I do that?
i am uncertain if we can do this in a wordpress way .. but here is the workaround --
$no_of_posts = 5;
$post_counter = 0;
if(is_Category('instagram') && ($no_of_posts<=$post_counter)) {
// bunch of code
$post_counter++;
}
untested but something like could get you going