How to implement the slider card in Carosol 3 using PHP? - javascript

Note: I am not promoting the products listed on the screenshot as it is not functional yet.
I am making a Woocomerence+Worpress site theme to my customer and i code it with pinegrow editor.
I have tree owls carousel slider in main page and its front-page.
Carousel 1 purpose = Show customer latest product, what are added. Left to right
Carousel 2 purpose = Show customer most highest rated product. Left to right
Carousel 3 purpose = Show customer products that are on sale. Left to right
Problem = my php.code works but don't go to right cards in slider, Do I need own codes for each card?, or is there better way to do it? and how I can change code to make Carousel 2 and 3 work like it
description.
<div class="card-body">
<?php
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 3,
'orderby' =>'date',
'order' => 'DESC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<div class="span3">
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="My Image Placeholder" width="65px" height="115px" />'; ?><h4><?php the_title(); ?></h4><span class="price"><?php echo $product->get_price_html(); ?></span></a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
Arvosteluja: <?php echo $product->get_review_count(); ?>
</div>
<!-- /span3 -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>

Related

How to create a new div for a custom tag in Blogger?

I have a site on Blogger. I share book quotes on this site. At the same time, as of today, I started to share poems. The section below shows all my posts:
I want to create a separate area for poems and show the publications with the tag "Poetry" here. What should I do?
I imagine you are using WordPress to create your blog, in this case you need to create a loop by calling some variables that you want to display, such as number of posts, titles, thumbnail, etc.
Below I will leave a snippet of my website code and a print of how it is displayed on the front-end
<div>
<?php query_posts( array( 'post_type'=> 'noticias', 'posts_per_page' => 1, 'orderby' => 'title', 'order' => 'ASC' ) ); ?>
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" style="text-decoration: none; color: #303030;">
<?php the_post_thumbnail('medium', array('class' => 'indicacao')); ?>
<div>
<h5><?php the_title(); ?></h5>
</div>
</a>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</div>
I suggest you take a look at the WordPress documentation and the forum, where you can get more information about it.
If not WordPress, please provide more information about your code.

How to fix image not displaying in php?

So I am trying to create a CTA(call to action) adding three cards into my wordpress site. I am trying to insert PHP and ACF functions so that it shows my image, currently it displays the title and the body text of these cards but doesn't show any image? How do I fix it?
In my acf, I have created four sub field types: "cta_image", "cta_title", "intro_text" and "cta_link". In my code editor, I have inserted the following functions and so far on my wordpress site, it shows the title and the intro text but I don't know how to put an image.
<?php
if ( have_rows( 'ctas' ) ) :
// Loop through rows (parent repeater).
while ( have_rows( 'ctas' ) ) :
the_row();
?>
<div class="title-wrapper">
<?php if ( get_sub_field( 'cta_title' ) ) : ?>
<h2><?php the_sub_field( 'cta_title' ); ?></h2>
<?php endif; ?>
</div>
<div class="body-text">
<?php print_r(get_sub_field('intro_text')); ?>
</div>
<?php
endwhile;
endif;
?>
Every time I insert functions to show the image, it gives a database error or simply doesn't show any image. The final work is supposed to look like the image down below. Mine shows just the title and body text all in a single line.
Have you tried using this bit of code directly from the documentation?
<?php $image = get_sub_field('cta_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>

How to add pagination in wordpress when using this code?

I'm using this code to show post loop on my homepage.
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
endif;
?>
And my content.php contain this code:
<div class='post-outer'>
<h2 class='entry-title'>
<a href='<?php echo get_permalink(); ?>' id='pt'><?php the_title(); ?></a>
</h2>
<div class='pimg'>
<img alt='featured image' id='fimg' src='<?php the_post_thumbnail_url(); ?>'/>
</div>
<div class='post-inner'>
<?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 25 ) ); ?>
<a href='<?php echo get_permalink(); ?>'>[Continue Reading]</a>
</div>
<div class='clear'></div>
</div>
I'm trying to add pagination in this code by showing only 5 post at a time in loop and adding next page option in it.
if you want with previous and next pages try this:
the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => __( 'Back', 'textdomain' ),
'next_text' => __( 'Onward', 'textdomain' ),
) );
or if you want without previous and next pages:
the_posts_pagination( array( 'mid_size' => 2 ) );
after endwhile and endif .
and for setting post per page, go to Setting > Reading and set number in 'Blog pages show at most' field.
and here the complete pagination reference: Pagination
hope to be useful!

WordPress expanding grid with thumbnail

I'm using codrops solution to display team members in an expanding grid: http://tympanus.net/codrops/2013/03/19/thumbnail-grid-with-expanding-preview/
I was already able to change some code to display my post thumbnail in the grid preview. However, I want to display the same picture in full size in the expanded view. In the original version it grabs an image in the files called 1.jpg. How can I achieve to grab my thumbnail?
Here is my PHP/HTML:
<ul id="og-grid" class="og-grid">
<?php $args = array( 'post_type' => 'mitarbeiter');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<a href="mailto:<?php the_field('email')?>" data-largesrc="images/1.jpg" data-title="<?php the_title(); ?>" data-description="<?php the_field('funktion') ?><br /><br />Rufen Sie mich an unter <?php the_field('telefonnummer')?> oder schreiben Sie mir eine Nachricht.">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('team');
}
else { } ?>
</a>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
Original CSS is just slightly changed to fit my needs: https://github.com/codrops/ThumbnailGridExpandingPreview/blob/master/css/component.css
No changes on original JS: https://github.com/codrops/ThumbnailGridExpandingPreview/blob/master/js/grid.js
Please have al look at your code:
data-largesrc="images/1.jpg"
Change this to your thumbnail url.

Bring a WordPress post dynamically

I've been trying to make this feature work for many days now and it's driving me nuts!
I have a single page theme in WP and in one of them there is a div on the left with a list of the posts in the site and on the right, a div that should display the content of the clicked post.
I found this question and followed up the linked tutorial and was partially successful.
I managed to bring the content dinamically, and all I want is being displayed but it seems the order of the tasks are wrong. Heres how it's acting:
I click on the link.
the current content goes away.
the loading span appears correctely.
the SAME content fades in.
after 1 second or so the current content is replaced with the new content and the address bar does not change at all.
Here's the code I have:
atracoes.js
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('.controle nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href)){
var aCarregar = hash+'.html #atr-conteudo';
$('#atr-conteudo').load(aCarregar)
}
});
$('.controle nav li a').click(function() {
var aCarregar = $(this).attr('href')+' #atr-conteudo';
$('#atr-conteudo').hide('fast',carregarConteudo);
$('#carregando').remove();
$('#atracoes').append('<span id="carregando">Carregando...</span>');
$('#carregando').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href'));
function carregarConteudo () {
$('#atr-conteudo').load(aCarregar,'',mostrarNovoConteudo());
}
function mostrarNovoConteudo () {
$('#atr-conteudo').show('normal',esconderCarregando());
}
function esconderCarregando () {
$('#carregando').fadeOut('normal');
}
return false;
});
});
index.php (the dynamic content part)
<div class="main" id="atracoes">
<div class="controle">
<nav>
<?php
$args = array( 'posts_per_page' => 20);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<?php the_title(); ?>
</li>
<?php endforeach;
wp_reset_postdata();?>
</nav>
</div>
<div id="atr-conteudo">
<?php the_post_thumbnail(); ?>
<div id="atr-texto">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
</div>
single.php (the part I'm plucking with ajax)
<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(); // Fullsize image for the single post ?>
</a>
<?php endif; ?>
<!-- /post thumbnail -->
<div id="atr-texto">
<!-- post title -->
<h1>
<?php the_title(); ?>
</h1>
<!-- /post title -->
<?php the_content(); // Dynamic Content ?>
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
</div>
</article>
You're calling the functions before you pass them to jQuery to execute, instead of allowing jQuery to execute them:
function carregarConteudo () {
$('#atr-conteudo').load(aCarregar,'',mostrarNovoConteudo);
}
function mostrarNovoConteudo () {
$('#atr-conteudo').show('normal',esconderCarregando);
}
(Notice they no longer have () after the function names)

Categories

Resources