I'm making a productscreen, I've made a Paint example what i've in mind.
The big black block is the productView with an sliding container in the back. I want to alphabetically order those products (All these little roundend blocks are products in a divs). But this order is "A" from beginning and 'Z' to end of slindingcontainer.
I want to order the products like the red line. I now have a second container with an modules, only this breaks my code.
Is there an other way to order the products like my example drawing?
Update - My code now:
<?php
if(!empty($productByType)){
for($i=0;$i < count($productByType); $i++){
$id = $productByType[$i]['id'];
$title = $productByType[$i]['title'];
$img = base_url('/img/producten/'.$productByType[$i]["img"]);
if($i % 2 == 0){
echo '<div class="seperatorforproduct">';
//0,2,4,6,8
}
============
Content divs
**Example of one product:** (Using modal from bootstrap)
echo '<div class="button btnstyle">';
echo '<div class="imgbtn">';
// <!-- Picture-->
echo '<img src="'.$img.'" title="'.$title.'" alt="'.$title.'" data-toggle="modal" href="#modal'.$id.'" />';
echo '</div>';
echo '<div class="txtbtn txtstyle">';
echo '<a class="btn" data-toggle="modal" href="#modal'.$id.'" >'.$title.'</a>';
echo '</div>';
echo '</div>';
?>
<div class="modal" style="display:none;" id="modal<?=$id?>">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h2><?=$title?></h2>
</div>
<div class="modal-body">
<div class="modal-left">
<img src="<?=$img?>" title="<?=$title?>" alt="<?=$title?>" />
</div>
<div class="modal-right">
<p><?=$productByType[$i]['info']?></p>
</div>
</div>
<div class="modal-footer">
Telephone number etc.
</div>
</div>
============
<?php
if($i % 2 == 1 || $i == count($productByType)){
// 0,3,6,9,12
echo '</div>';
}
}
}?>
Check this http://jsfiddle.net/Mzmay/18/
Using PHP you generate the markup like that in fiddle & later you can use the jQuery to do that. I am not sure how to do the same by just using Php.
Related
I'm using bootstrap 4 (I also tried using the bootstrap 3) and I think I have a buggy modal because when I add something in anchor tag href it causes it to break down like having its content changed same with my main page or it just shows and disappeared. Here's my modal and my anchor tag looks(my modal is in my packages.php while the anchor tag is inside a function which is in packageclass.php):
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
packageclass.php
public function GetAllData($getTbl){
try{
$query = $this->dbconn->prepare("SELECT * FROM tblpackages P JOIN tblpackageincluded I ON P.PackageID = I.PackageID JOIN tblrates R ON P.PackageID = R.PackageID");
$query->execute();
if($query->rowCount() > 0){
while ($row = $query->fetch(PDO::FETCH_ASSOC)){
if($getTbl == 1){
echo "<tr>";
echo "<td>". $row['PackageID'] ."</td>";
echo "<td><a href='DeletePackages.php?id=". $row['PackageID'] ."'><i class='fas fa-trash-alt'></i></a></td>";
echo "<td><a href='EditPackages.php?id=". $row['PackageID'] ."'><i class='fas fa-edit'></i></a></td>";
echo "<td>". $row['PackageName'] ."</td>";
echo "<td>". $row['PackageCost'] ."</td>";
echo "<td>". $row['PackNote'] ."</td>";
echo '<td> <i class="fas fa-eye"></i></td>';
echo '<td> <i class="fas fa-eye"></i></td>';
echo "</tr>";
}
else if($getTbl == 2){
echo "<tr>";
echo "<td>". $row['PackageIncID'] ."</td>";
echo "<td>". $row['PackIncluded'] ."</td>";
echo "</tr>";
}
else if($getTbl == 3){
echo "<td>". $row['RateID'] ."</td>";
echo "<td>". $row['RateCount'] ."</td>";
echo "<td>". $row['CostPerHead'] ."</td>";
}
}
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
Thankyou
Image of the modal after 1 second it looks like this
You have a conflict:
<a> tags cause a postback.
Modals appear immediately on click driven by js
You have set up the anchor to both display the modal and then postback to retrieve the data which probably has the effect of
closing the original modal,
retrieving the data,
then building a new modal-body table
which won't get displayed until you click the anchor...which starts the process over again.
What to do?
You need to remove the conflict. You can...
Postback and retrieve the data, populate the modal-body, then auto display the modal via js on document ready. -OR-
On Client side click retrieve the data via ajax and populate a dynamic table during the modal show event.
If you use the postback option you can do everything as you are now with PHP. You need to remove the modal display from anchor tag and trigger it in the jquery ready function or whatever ready method you prefer. This is not a very clean way to do it but it is an option.
If you choose the Client side option, you may want to consider a third party dynamic table add-in. This, in my opinion, is the better option for use with a Bootstrap modal.
I have created a database to access the images inside a slider which uses jquery. The problem starts when I try to insert the connection given that it is an array:
<?php
$slides = array(
'<div data-thumb="images/slider/slides/image1_small.jpg" data-src="images/slider/slides/image1.jpg">
<div class="camera_caption fadeFromBottom">
Text 1 below image
</div>
</div>',
'<div data-thumb="images/slider/slides/image2_small.jpg" data-src="images/slider/slides/image2.jpg">
<div class="camera_caption fadeFromBottom">
Text 2 below image
</div>
</div>',
'<div data-thumb="images/slider/slidesimage3_small.jpg" data-src="images/slider/slides/image3.jpg">
<div class="camera_caption fadeFromBottom">
Text 3 below image
</div>
</div>'
);
shuffle($slides);
foreach ($slides as $slides) {
echo "$slides\n";
}
?>
My question is, is there a way to change that array to access the images and the text? I've tried with a while loop but couldn't figure it out.
Update: What I want is to change the array to
<?php
$query = "SELECT * FROM tblslider";
if ($result=mysqli_query($connection, $query)) {
while ($slides = mysqli_fetch_array($result)) {
'<div data-thumb="images/slider/slides/<? echo $row_DataSlider['strImagesmall'] ?>" data-src="images/slider/slides/<? echo $row_DataSlider['strImage'] ?>">
<div class="camera_caption fadeFromBottom">
<? echo $row_DataSlider['strText'] ?>
</div>
</div>'
}
}
?>
obviously this is not possible but im looking for a solution to get something like it
I believe you have a typo in your foreach...foreach ($slides as $slides) (using $slides twice)
I'd put:
foreach ($slides as $s) {
echo $s . "</br>";
}
i have a single page website built on wordpress (twenty-thirteen-child template).
header content footer.
and 3 posts categories :category A category B category C.
i need to split the content into these 3 categories/sections -like this
<div class="section_top">
all the posts from category A
</div>
<div class="section_mid">
all the posts from category B
</div>
<div class="section_bot">
all the posts from category C
</div>
i got a little confused when i started to read about the wordpress main loop ,query_posts and WP_Query,eventually i have this code replacing the main loop ,so my questions are :
1 is this the correct way to do it?
2 how to give each section a unique class since i need to style each section diffrently?
here is the code (index php(in child theme)
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
$args = array('category__in' => array(catA,catB,catC));
$category_posts = new WP_Query($args);
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<div id="<?php
foreach((get_the_category()) as $category) {echo $category->cat_name . ' ';}?>"
class="post-item">
<div class="post-info">
<h2 class="post-title">
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h2>
</div>
<div class="post-content">
<?php the_content(); ?>
</div>
</div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
The problem with how you're trying to solve it is that all posts are still shown chronologically, so this could happen:
Category A post 12/01
Category B post 09/01
Category A post 05/01
What I'd recommend: make 3 different WordPress loops querying each category separately like so:
<div class="section_top">
WordPress loop for all the posts from category A
</div>
<div class="section_mid">
WordPress loop for all the posts from category B
</div>
<div class="section_bot">
WordPress loop for all the posts from category C
</div>
Example of such a loop:
// The Query
$the_query = new WP_Query('category_name=categoryA');
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
Difference between get_the_...() and the_...()
When you use functions like get_the_title() you are able to store them in a PHP variable like so:
$title = get_the_title();
echo strtoupper($title); //do something with it later
When you use functions like the_title() then the title is immediately printed on the page, so there's no need for an echo statement:
the_title();
Notice: the_permalink() has a function get_permalink(), the function get_the_permalink() does not exist. Don't ask my why ;)
I have installed a plugin which is custom post type, I am trying to use the previous_post_link() and next_post_link() to get previous and next posts.
It is working fine but the only problem is that I am placing it in my 4th div container where as it always sits on top of page right after div "entry-content".
Is it a known issue?
Here is the piece of code:
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
$tmp = '<div id="wpmtp-single-wrap">';
$tmp .= '<div class="wpmtp-vcard">';
$tmp .= '<div class="wpmtp-vcard-left">';
$tmp .= wpmtpv2_featured_img($post->ID);
$previous = previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
$next = next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
// $tmp .= '<div class="wpmtp-goback">go back</div>';
// $tmp .= '<div class="wpmtp-gonext">view next</div>';
$tmp .= $previous;
$tmp .= $next;
$tmp .= '</div>';
...........
..........
..........
........
return $tmp;
}
If I place the commented html code instead or previous and next functions, it works fine. Which mean that html and css are right in place, and the problem is in the functions I guess.
And this is what I get after inspecting it in firebug:
<article .....>
<h2 .....></h2>
<div class="meta"></div>
<div class="entry-content">
<a href="link to next" rel="prev">
<div class="wpmtp-gonext">view next</div>
</a>
<a href="link to previous" rel="next">
<div class="wpmtp-goback">go back</div>
</a>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
.....
....
....
....
try this code:
<?php
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
?>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
<?php echo wpmtpv2_featured_img($post->ID); ?>
<div class="wpmtp-goback"><?php previous_post_link( '%link', __( ' go back', 'twentyeleven' ),TRUE ); ?></div>
<div class="wpmtp-gonext"><?php next_post_link( '%link', __( 'view next', 'twentyeleven' ),TRUE ); ?></div>
<?php
// replace **twentyeleven** with your theme name
//or try with this line
//previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
//next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
?>
</div>
<?php
.........
.........
........
return $tmp;
}
or best to try this plugin : wp-pagenavi
This plugin provides the wp_pagenavi() template tag which generates fancy pagination links.
thanks
I am trying to load an Image Slider images from a Custom Post Type image Gallery Feature. For example let say I have an Custom Post Type called banner which I can load images to it's Gallery and I have an HTML code like this:
<div class="item active">
<img src="assets/img/ban1r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
<div class="item active">
<img src="assets/img/ban2r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
Can you please let me know how I can use the custom WP_Query to retrive the images from the custom post and load them into slider instead of above HTML?
So far I have done something like this but it is not displaying any image!
<?php
$args = array( 'post_type' => 'banner');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$gallery = get_post_gallery_images($post);
foreach( $gallery as $image ) {
echo '<div class="item active">';
echo '<img src="' . $image . '">';
echo '</div>';
}
endwhile;
?>
I tried something like this before 2 months ago, and working great for me.
global $wpdb;
$query = "select * from $wpdb->posts
where
post_type = 'banner' and
post_status = 'publish'";
$results = $wpdb->get_results($query, ARRAY_A);
foreach( $results as $result ){
echo '<div id="'.$result['ID'].'" class="listen">';
echo get_the_post_thumbnail( $result['ID'], array(200, 200) );
</div>';
}
Take a look on get_the_post_thumbnail