Can you please advise which is the most appropriate way to append classes dynamically to the 's below based on the ID of the post?
The goal is to add a class to some of the div's depending on the ID of the post being even or odd.
<div class="service__preview">
<div class="row mb-5">
<div class="col-4">
<div class="row">
<div class="col-5 // here I want to dynamically add order-2 if get_the_ID() is even">
<div class="service__preview service__preview-id">
<?php echo get_the_ID() + 1;?>
</div>
</div>
<div class="col-7 // here I want to dynamically add order-1 if get_the_ID() is even">
<div class="service__preview service__preview-icon">
<div class="icon__container icon__container-3x">
<div class="icon__container icon__container-2x">
<div class="icon__container icon__container-1x">
<i class="<?php echo get_post_meta($post->ID, 'service_icon', true); ?> fa-2x"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-1">
</div>
<div class="col-6">
<a class="service__preview service__preview-title" href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<p class="service__preview service__preview-description"><?php the_content(); ?></p>
<a class="service__preview service__preview-link" href=" <?php the_permalink(); ?>"><p>Learn more</p></a>
</div>
</div>
Looking forward to your suggestions.
FYI: the project is a WordPress template.
So I'm converting bootstrap site to Wordpress and post cards don't want to stack horizontally... I know there should be foreach loop which will loop through posts but I don't know how to set it up...
<?php while(have_posts()) {
the_post();
?>
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
</div>
</div>
</section>
<?php } ?>
while is also a loop. Inside the loop, you can just put the repeated code. As I've understood your code than you need to something like this:
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<?php while( have_posts() ) {
the_post();
?>
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
Also, better to move code for one block to another file for example partials/post.php:
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
</div>
And update your current file:
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<?php while( have_posts() ) {
the_post();
get_template_part( 'partials/post' );
} ?>
</div>
</div>
</section>
I am VERY new to PHP and editing some code
Currently it has two radio buttons. Selecting either will bring up some options.
I am wanting to get rid of one option (pick up) and have the page just show the delivery option.
Any help would be ace, I have tried playing with the code but no luck!
<div class="top10 row">
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>"delivery"
));
?>
<span><?php echo Driver::t("Delivery")?></span>
</div> <!--col-->
</div> <!--row-->
<div class="delivery-info top20">
<div class="row">
<div class="col-sm-6">
<?php echo CHtml::textField('contact_number','',array(
'class'=>"mobile_inputs",
'placeholder'=>Driver::t("Contact nunber"),
'maxlength'=>15
))?>
</div> <!--col-->
<div class="col-sm-6 ">
<?php
echo CHtml::textField('email_address','',array(
'placeholder'=>Driver::t("Email address")
))
?>
</div> <!--col-->
</div> <!--row-->
<div class="row top10">
<div class="col-sm-6 ">
<?php echo CHtml::textField('customer_name','',array(
'placeholder'=>Driver::t("Name"),
'required'=>true
))?>
</div>
<div class="col-sm-6 "><?php echo CHtml::textField('delivery_date','',array(
'placeholder'=>Driver::t("Delivery before"),
'required'=>true,
'class'=>"datetimepicker"
))?></div>
</div> <!--row-->
<div class="row top10">
<div class="col-sm-12 ">
<?php
$map_provider = Driver::getMapProvider();
?>
<?php if ($map_provider =="mapbox"):?>
<div id="mapbox_delivery_address" class="mapbox_geocoder_wrap"></div>
<?php elseif ( $map_provider=="google.maps"):?>
<?php
echo CHtml::textField('delivery_address','',array(
'class'=>'delivery_address geocomplete delivery_address_task',
'placeholder'=>Driver::t("Delivery Address"),
'required'=>true
));
?>
<?php endif;?>
Remove the lines of code below (or comment them out while you try it). Make a copy of the file before you make any changes in case you need to back out the attempt.
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>
I have a page where i listed a posts from a database and I want to do that when i clicked a specific post it redirect me to another page with blank area where is more details with ID of this post. I don't know how to do that the blank area will which post were clicked. (Sorry for my english)
<div class="row">
<?php
foreach ($viewmodel as $item) : ?>
<div class="col-sm-4">
<div class="card shadow">
<div class="card-header border-dark shadow"><?php echo $item['TITLE']; ?></div>
<div class="card-body">
<p class="card-text"><?php echo $item['DESCRITIONS']; ?></p>
<a class="btn badge-secondary btn-sm" type="submit"
href="<?php echo ROOT_PATH; ?>shares/zobaczZadanie">More</a>
</div>
<div class="card-footer">
<small class="text-muted"><?php echo $item['DATE']; ?></small>
</div>
</div>
</div>
<?php endforeach; ?>
But I don't have acces to specific post
I'm developing a website in wordpress and I want to load more news when scrolling but I already have a html structure and when I put ajax load more it put own structure and I don' want that.
I'm using the Ajax Load More plugin.
So, How can I use Ajax load more with this html structure:
<?php
$posts = get_posts(['cat' => get_cat_ID("news")]);
foreach($posts as $post){
setup_postdata($post);
?>
<div class="col-xs-12 col-sm-6 col-md-4">
<a class="news-link" href="<?php the_permalink() ?>">
<div class="news">
<div class="image">
<?php the_post_thumbnail('thumbnail') ?>
<div class="mask">
<div class="icon">
<i class="icon-plus"></i>
</div>
</div>
</div>
<div class="title">
<span>
<?php the_title(); ?>
</span>
</div>
<div class="excerpt">
<p class="date">
<?php echo get_the_date('Y-m-d'); ?>
</p>
</div>
<div class="excerpt">
<p>
<?php the_excerpt(); ?>
</p>
</div>
</div>
</a>
</div>
<?php
wp_reset_postdata();
} ?>
If i put this shortcode it shows but not with the structure that i want.
[ajax_load_more id="7279302844" container_type="div" post_type="post" category="news"]
Thank you