Getting Same Description in All the Custom Taxonomy Posts - custom-post-type

I have developed a custom taxonomy post type. I have displayed categories & inside categories posts (products).
I am getting the Post title & Image as they should be (which I add), but the descriptions of all the posts are same.
I have no idea why same desc keeps displaying, even though everything else is dynamic.
Here is the code I am using:
$taxID = get_queried_object()->term_id;
$args = array(
'post_type' => 'industrial_product',
'fields' => 'ids',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'industrial_product_cat',
'terms' => $taxID,
'field' => 'term_id',
'operator' => 'IN'
)
),
);
$query = new WP_Query($args);
if ($query->have_posts()):
$i=1;
foreach( $query->posts as $id ):?>
<div class="row mb-4">
<div class="col-md-4 col-12">
<?php
$image_palette = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'single-post-thumbnail' );
?>
<img src="<?php echo $image_palette[0]; ?>" alt="" class="img-fluid" style="max-width:100%;">
</div>
<div class="col-md-8 col-12">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item m-0" role="presentation">
<a class="nav-link active c-2" id="productInfo<?php echo $i;?>-tab" data-toggle="tab" href="#productInfo<?php echo $i;?>" role="tab" aria-controls="productInfo<?php echo $i;?>" aria-selected="true">Product Information</a>
</li>
<li class="nav-item m-0" role="presentation">
<a class="nav-link c-2" id="std_tds<?php echo $i;?>-tab" data-toggle="tab" href="#std_tds<?php echo $i;?>" role="tab" aria-controls="std_tds<?php echo $i;?>" aria-selected="false">STD / TDS</a>
</li>
</ul>
<div class="tab-content p-3" id="myTabContent<?php echo $i;?>">
<div class="tab-pane fade show active" id="productInfo<?php echo $i;?>" role="tabpanel" aria-labelledby="productInfo<?php echo $i;?>-tab">
<h5><?php echo get_the_title($id); ?></h5>
<p><?php echo get_the_content($id); ?></p>
</div>
<div class="tab-pane fade" id="std_tds<?php echo $i;?>" role="tabpanel" aria-labelledby="std_tds<?php echo $i;?>-tab">
<?php
if(get_field('std_tds_description', $id)){
the_field('std_tds_description', $id);
}
else{
echo "No, Content.";
}
?>
</div>
</div>
</div>
</div>
<?php
$i++;
endforeach;
endif;
//
}
?>
Here is a screenshot of the result:
Can somebody point out what is the problem here. I've tried all sort of stuff but It still shows same desc.
Thanks & Sorry If I'm doing something stupid, still learning!

I just changed the call
Old: <?php echo get_the_content( $id ); ?>
New: echo get_post_field('post_content', $id);
Don't know what was wrong but, It worked.

Related

highlighting selected number in pagination

I used the following code in my website to highlight clicked page number, but all numbers are highlighted either with clicking or not. How can I solve that?
//===================start pagination=========================
$jumpForward=3;
$jumpBackward=3;
$active=isset($_GET['page'])&&$_GET['page']==$pageNum?'active':'';
?>
<nav aria-label="Page navigation example" class="pagination-container">
<ul class="pagination pagination-lg">
<?php if( ($pageNum-$jumpBackward)>=1 ){ //previous
?> <li class="page-item"><a class="page-link prev" href="?page=<?php echo ($pageNum-$jumpBackward)?>">Previous (-3)</a></li> <?php
}else{
?> <li class="page-item disabled"><a class="page-link">Previous</a></li> <?php
}
for ($page=max(1,$pageNum-5);$page<=min($pageNum+2,$NumberOfPages);$page++) { //for loop
echo '<li class="page-item '.$active.'"><a class="page-link" href="search.php?scat='.$scat.'&c='.$count.'&i='.$catid.'&n='.$catName.'&page='.$page.'">'. $page.'</a></li>';
}
if(($pageNum+$jumpForward)<=$NumberOfPages ){ //next
?> <li class="page-item"> <a class="page-link next" href="?
page=<?php echo ($pageNum+$jumpForward)?>" >Next (+3)</a> </li> <?php
}else{
?> <li class="page-item disabled"> <a class="page-link " >Last</a> </li> <?php
}
?>
</ul >
</nav>
<?php
}

My Question How i put my code to Models and Controler Codeigniter4

i make navbar dinamic from my table i want to take my code view to models and controler but i stuck in there i just can created in my view
My code
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<?php
$db = \Config\Database::connect();
$builder = $db->table('navbar');
$navbar = $builder->where('parent_id', '0')->where('status', '1')->orderBy('id_nav', 'ASC')->get()->getResultArray();
?>
<?php foreach ($navbar as $menu) : ?>
<?php
$db = \Config\Database::connect();
$builder = $db->table('navbar');
$subnav = $builder->where('parent_id', $menu['id_nav'])->where('status', '1')->orderBy('id_nav', 'ASC')->get()->getResultArray();
?>
<?php if ($subnav != Null) : ?>
<?php foreach ($subnav as $nav) : ?>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-toggle" href="#" id="dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?= $menu['nav_name']; ?></a>
<div class="dropdown-menu" aria-labelledby="dropdown" style="border: 0px solid; background:#f8f9f9;">
<a class="dropdown-item" href="#"><?= $nav['nav_name']; ?></a>
</div>
</li>
<?php endforeach ?>
<?php else : ?>
<li class="nav-item active">
<a class="nav-link" href="#"><?= $menu['nav_name']; ?> <span class="sr-only">(current)</span></a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
<form class="form-inline my-2 my-md-0">
<a class="navbar-brand" href="">
<button class="btn btn-sm btn-outline-danger my-2 my-sm-0" type="submit">LOGIN</button>
<button class="btn btn-sm btn-outline-success my-4 my-sm-0" type="submit">JOIN ME</button>
</a>
</form>
</div>
</div>
</nav>
code
My Question How i put my code to Models and Controler Codeigniter4
This might help you get started How to
Read the documentation it explains everything now that it was updated.
Moreover it seems that you do not have any idea what an MVC pattern is since you are loading the db in the view. I might start from there. Model-View-Controller

getVar() from selected option input codeigniter 4

I have view
<!-- input-text -->
<div class="form-group">
<?php $name = 'name';
$placeholder = 'Nama Lengkap';
$value = old($name); ?>
<label for="<?= $name; ?>"><?= $placeholder; ?></label>
<input type="text" class="form-control <?= ($validation->hasError($name)) ? "is-invalid" : ''; ?>" id="<?= $name; ?>" name="<?= $name; ?>" placeholder="<?= $placeholder; ?>" value="<?= $value ?>">
<div class="invalid-feedback">
<?= $validation->getError($name); ?>
</div>
</div>
<!-- input-select -->
<div class="form-group">
<?php $name = 'gender';
$placeholder = 'Jenis Kelamin';
$value = old($name); ?>
<label for="<?= $name; ?>"><?= $placeholder; ?></label>
<select name="<?= $name; ?>" class="selectpicker form-control" data-live-search="true" id="<?= $name; ?>">
<option value="0">Laki-laki</option>
<option value="1">Perempuan</option>
</select>
</div>
and controller
public function create(){
dd($this->request->getVar());}
it show only name, but gender doesn't. How to show the value of selected option in CodeIgniter 4?
when you try to catch your post in controller u should type the name variable of the input
public function create(){
dd($this->request->getVar('gender'));
}
Use form helper, try it:
<div class="form-group">
<label for="name">Nama Lengkap</label>
<?php echo form_input('name', set_value('name'), 'class="form-control" placeholder="Nama Lengkap"'); ?>
<?php if(!empty($errors)){ ?>
<em class="text-danger"><?php echo $errors->getError('name') ?></em>
<?php } ?>
</div>
<div class="form-group">
<label for="gender">Jenis Kelamin</label>
<?php echo form_dropdown('gender', ['0' => 'Laki-laki', '1' => 'Perempuan'], [], 'class="form-control"'); ?>
</div>
Hope it helpful, cheers...

How to display 5 columns per row in Opencart?

How to display 5 columns per row in opencart?
What I have tried is Extensions -> Modules ->Featured then edit the module. I have changed the limit to 5 and decreased the width and height but after changing it displays the same. I am not able to get five columns per row. Please suggest me how to acheve it.
Thank you.
Here is my popular.tpl file in catalog/view/theme/promoglasses/template/module
<div class="tab-title">
<h2>Popular Products</h2>
<ul class="tabs tabs-popular-products tab_categorys">
<li class="active" rel="tab129-popular-products">POPULAR Products</li>
</ul>
</div>
<br />
<br />
<br />
<div class="row">
<?php foreach ($products as $product) { ?>
<div class="product-layout col-sm-5ths">
<div class="product-thumb transition">
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></div>
<div class="caption">
<h4><?php echo $product['name']; ?></h4>
<div class="label-cont"> As low as </div>
<div class="label-price">
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="label-sup">
<b>
<sup>(C)</sup>
</b>
</div>
<br />
<p><?php echo $product['description']; ?></p>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
For the CSS part here I have written the code for class col-sm-5ths:
.col-sm-5ths {
float: left;
width: 20%;
min-height: 1px;
position: relative;
}

How to add a custom wordpress isotope project portfolio pagination

How can I add a pagination to my isotope portfolio page?
I want each filter work with a max item of 8 and use pagination to check next 8 items.
Below is my custom Template Name: Portfolio
<?php $t =& peTheme(); ?>
<?php $title = get_the_title(); ?>
<?php $pcontent = get_the_content(); ?>
<?php $pcontent = apply_filters( 'the_content', $pcontent ); ?>
<?php $project =& $t->project; ?>
<?php list($portfolio) = $t->template->data(); ?>
<?php $content =& $t->content; ?>
<div class="container">
<div class="row">
<div class="span12">
<h1><?php echo $title; ?></h1>
</div>
</div>
<div class="row">
<div class="span12">
<nav class="portfolio-filter clearfix">
<ul>
<?php $project->filter('',"keyword"); ?>
</ul>
</nav>
</div>
<hr class="main-hr-sm">
<?php echo $pcontent; ?>
</div>
<div class="row portfolio-container">
<?php while ($content->looping()):
$meta =& $content->meta(); ?>
<div class="span3 portfolio-item <?php $project->filterClasses(); ?>">
<a href="<?php echo $t->image->resizedImgUrl($content->get_origImage(),1000,1000); ?>" class="fancybox" data-portfolio="<?php $content->slug(); ?>">
<img src="<?php echo $t->image->resizedImgUrl($content->get_origImage(),460,300); ?>" alt="<?php echo esc_html(get_the_content()); ?>">
</a>
<div class="caption">
<?php $content->content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
Pagination isn't built into Isotope so you'd have to build it from the ground up. Here is a good tutorial on how to do that with Wordpress and Isotope v1. Keep in mind the tutorial is using Isotope v1 so you'll have to change it if you want to use Isotope v2 but the general concepts in the tutorial should still be very helpful.

Resources