I am looking at this example : https://wordpress.stackexchange.com/questions/95661/open-wordpress-posts-in-bootstrap-modal
but don't seem to understand the principal of this. I have my posts displaying as a masonry grid on the front page with this loop:
<?php query_posts('posts_per_page=25'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<a href="<?php echo the_permalink(); ?>" class="box col<?php echo rand(2,3); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<?php endwhile; endif; ?>
which when clicked is opening the single-content.php:
<?php while (have_posts()) : the_post(); ?>
<article <?php post_class(); ?>>
<?php the_title(); ?>
<?php get_template_part('templates/entry-meta'); ?>
<?php the_content(); ?>
</article>
<?php endwhile; ?>
I have been trying to get the single-content in a bootstrap modal window when a thumbnail of the masonry grid is being clicked. No luck when experimenting with different content on the web, any guidance would be appreciated.
best of wishes
O.
EDIT:
<?php query_posts('posts_per_page=25'); ?> <!-- posts per page -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<span class="new-wrapper">
<span><h1><?php the_title(); ?></h1></span>
<a href="<?php echo the_permalink(); ?>" class="box col<?php echo rand(2,3); ?>"> <!-- randomize .col2 & .col3, creating the grid portfolio -->
<?php
$post_id = get_the_id();
if ( has_post_thumbnail() ) {
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img src="<?php echo $feat_image;?>">
<?php
}
?>
</span>
<?php endwhile; endif; ?>
<div class="modal fade" id="post<?php echo $post_id; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<!-- Here showing the title of the post -->
<h4 class="modal-title" id="myModalLabel"><?php
the_title();
?></h4>
</div>
<div class="modal-body">
<?php the_content() // the content is adding here ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
Am using your code, but it is only working on the first post and therefor not being dynamic. Clicking on all the other posts doesn't seem to have any effect.
<?php query_posts('posts_per_page=25'); ?>
<?php the_title(); ?>
<?php
$post_id = get_the_id();//make sure this getting the correct post id
//here change the direct thum to custom link like this
if ( has_post_thumbnail())
{
//here we can get the featured image of the post as a link
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); //make sure this will return the correct featured image url
//place the url in our custome html like this:
//in this we change the target as per the post id so each post have its own modal for show the content in the while loop.
?>
<img src="<?php echo $feat_image;?>">
<?php
}
// here the target is set as #post'current post id'
//here we starting the modal part
?>
<!-- Modal -->
<div class="modal fade" id="post<?php echo $post_id; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<!-- Here showing the title of the post -->
<h4 class="modal-title" id="myModalLabel"><?php
the_title();
?></h4>
</div>
<div class="modal-body">
<?php the_content() // the content is adding here ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<?php
?>
Here am trying to load the modal inside the while loop and change the name of the modal and the click trigger related to the post id. Suppose the post id is 1 then the trigger and the modal id is like #post1 and post1. Here avoid the permlink to the detail page. I hope that this will solve problem.
<?php
//Get Post ID
echo $id= get_the_ID(); ?>
link to open model
Read More
Bootsrap model
<div class="modal fade project-model" id="myModal<?php echo $id;?>" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><?php the_title(); ?></h5>
<button type="" class="close project-close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php the_content(); ?>
</div>
</div>
</div>
</div>
Related
I am using Bootstrap tabs to display a grid with employee profiles and photo's in ACF repeater fields and when clicking on the profile a bootstrap modal pops up with the information filled out in a repeater sub field.
Everything is working fine, but when you click on the different profiles, the same profile information is in the modal and not different profile information.
Here is my code
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
<div class="row justify-content-md-between">
<?php
if( have_rows('team_profile_boxes') ):
$i = 1;
// loop through the rows of data
while ( have_rows('team_profile_boxes') ) : the_row(); ?>
<div id="profile-box">
<div class="profile-image-box">
<div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
<div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
</div>
<div class="profile-details">
<a data-toggle="modal" href="#exampleModal">
<h4>
<span><?php the_sub_field('division_title'); ?></span>
<br>
<?php the_sub_field('profile_name'); ?> <br>
<span><?php the_sub_field('job_title'); ?></span>
</h4>
</a>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<?php the_sub_field('profile_information'); ?>
</div>
</div>
</div>
</div>
<?php $i++;
endwhile;
else :
// no rows found
endif;
?>
</div>
</div>
I've looked through this example but it doesn't seem to apply:
ACF Repeater + Modal
you have not print $i , try this code ...
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
<div class="row justify-content-md-between">
<?php
if( have_rows('team_profile_boxes') ):
$i = 1;
// loop through the rows of data
while ( have_rows('team_profile_boxes') ) : the_row(); ?>
<div id="profile-box-<?php echo $i; ?>">
<?php //your code ?>
</div>
<div class="modal fade" id="profile-box-<?php echo $i; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<?php //your code ?>
</div>
<?php $i++;
endwhile;
else :
// no rows found
endif; ?>
</div>
</div>
</div>
I managed to solve it using the philosophy above but using the following code:
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
<div class="row justify-content-md-between">
<?php
if( have_rows('team_profile_boxes') ):
$i = 1;
// loop through the rows of data
while ( have_rows('team_profile_boxes') ) : the_row(); ?>
<div id="profile-box">
<div class="profile-image-box">
<div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
<div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
</div>
<div class="profile-details">
<a data-toggle="modal" href="<?php echo '#exampleModal' . $i ?>">
<h4>
<span><?php the_sub_field('division_title'); ?></span>
<br>
<?php the_sub_field('profile_name'); ?> <br>
<span><?php the_sub_field('job_title'); ?></span>
</h4>
</a>
</div>
</div>
<div class="modal fade" id="<?php echo 'exampleModal' . $i ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<?php the_sub_field('profile_information'); ?>
</div>
</div>
</div>
</div>
<?php $i++;
endwhile;
else :
// no rows found
endif;
?>
</div>
</div>
you can use an acf build-in function called get_row_index() to set an index to all the rows. it starts from 1 and goes up to end of your rows count.
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
<div class="row justify-content-md-between">
<?php if( have_rows('team_profile_boxes') ):
// loop through the rows of data
while ( have_rows('team_profile_boxes') ) : the_row(); $i = get_row_index();?>
<div id="profile-box">
<div class="profile-image-box">
<div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
<div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
</div>
<div class="profile-details">
<a data-toggle="modal" href="#exampleModal-<?php echo $i;?>">
<h4>
<span><?php the_sub_field('division_title'); ?></span>
<br>
<?php the_sub_field('profile_name'); ?> <br>
<span><?php the_sub_field('job_title'); ?></span>
</h4>
</a>
</div>
</div>
<div class="modal fade" id="exampleModal-<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<?php the_sub_field('profile_information'); ?>
</div>
</div>
</div>
</div>
<?php endwhile; endif; ?>
</div>
</div>
I have 2 wordpress installations, 1 is for major content, the other is a help center.
the help center is installed in the major content directory. So you have the wordpress directory, and another in that directory, making it so we can use different themes and change the look between the two.
I'm just curious, on the search results page, I'm getting the correct url's, but they are going to 404 pages. I verified in the database that these records exist, so it's not a matter of the database not making these records and that these pages don't exist. Another note is that the search results page will return pages that have been created, but
<?php
get_header();
global $wp_query;
$total_result = $wp_query->found_posts;
?>
<div class="main">
<div class="main-hero">
<div class="container">
<h1>Boxstorm Help Center</h1>
<p>Search the Boxstorm Help Center documentation</p>
<div class="search-wrapper">
<form id="searchform" class="searchform" role="search" method="get" action="<?php echo site_url(); ?>">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input id="s" name="s" type="text" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder', 'boxstorm' ); ?>" value="<?php echo get_search_query(); ?>">
<span class="search-button-wrapper">
<input id="searchsubmit" type="submit" value="">
<i class="fa fa-search"></i>
</span>
</div>
</form>
</div><!-- / .search-wrapper -->
</div>
</div><!-- /.main-hero -->
<nav class="main-hero-subnav cd-secondary-nav">
<div class="container">
<div class="is-hidden-mobile">
<?php get_breadcrumb(); ?>
</div>
</div>
</nav>
<div class="panel sub-nav-hero">
<div class="container page">
<div class="columns is-multiline is-mobile search-results">
<div class="column is-3-desktop is-6-tablet is-full-mobile left">
<div class="columns top-cats is-multiline is-mobile is-centered">
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/getting-started/">
<i class="fas fa-list-ul"></i>
<h2>Getting Started</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/documentation/">
<i class="fas fa-book"></i>
<h2>Documentation</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/videos/">
<i class="far fa-play-circle"></i>
<h2>Browse Videos</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/contact/">
<i class="fas fa-at"></i>
<h2>Contact Support</h2>
</a>
</div>
</div>
</div>
</div>
<div class="column is-9-desktop is-6-tablet is-full-mobile right">
<h1 class="results"><?php printf( __( 'Search results for: <b>%s</b>', 'boxstormsupport'), get_search_query() ); ?></h1>
<div class="columns is-multiline">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part( 'content', 'search' ); ?>
<div class="column is-12 results">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php the_permalink(); ?>
</div>
<?php endwhile; else : ?>
<div class="column is-12">
<p><?php _e( '<p>Sorry, but there were no results for the term <b style="font-weight:900;">'.get_search_query().'</b>. Please refine your search terms and try again.</p>' ); ?></p>
</div>
<?php endif; ?>
</div><!-- / columns -->
</div><!-- / columns is-9 right -->
</div><!-- / search-results -->
</div>
</div>
</div>
<?php get_footer(); ?>
The site is live at https://www.boxstorm.com/help-center. If you'd like to see the problem.
The pages follow this format in wordpress:
Pages parameters:
This is what I'm seeing:
Chrome
Firefox
Any help would be appreciated, thanks.
I've created a custom template then I've a query woocommerce product in that template using while() method. That's working fine. But I've added one bootstrap v3 modal in that query. That bootstrap modal using because if I have variable product and show Select Option for variation selection, then when user click 'select option', then, open bootstrap modal, I've successfully that work, but problem when open that modal show only one (latest) product, example: if I click select option for "Food one" then open modal and show latest last product, like "food one" but if I click "food two" then open modal and show same product in that modal like "food one".
Note: I have added that modal in first while() method. You can check that problem on our live server/site https://www.theitaliankitchen.com.bd/m/
You can check this screenshots
I have clicked "Agnolotti alla Piemontese" product
then open modal
Then I've clicked "Mascarpone" Product
Then Open same product
But i want to show which product I've clicked show only that product information in modal.
Here is my full custom template codes
<?php
/*
Template Name: Mobile Version
*/
get_header(); global $product;
$categorydesign = get_option( 'custom_category_options', array() );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
/**
* tokoo_before_main_content hook
*
* #hooked tokoo_wrapper_start - 10 (outputs opening divs for the content)
*/
do_action( 'tokoo_before_main_content' );
?>
<div class="shopmobile-version-area ">
<div class="shop-mobile-version column ">
<div class="msite-title-area fix">
<h2><?php echo bloginfo('name'); ?></h2>
</div>
<!-- Category Design Area-->
<div class="category-design-area fix">
<?php
if ( ! empty( $categorydesign['category_designgroup'] ) ) :
foreach ( $categorydesign['category_designgroup'] as $catdesign ) : ?>
<?php
$category_info = $catdesign['category_design_name'];
$cat_name = get_term_by('slug', $category_info, 'product_cat'); // get name by slug
$cat_link = get_term_link($cat_name->term_id); // get term link by id
$icon_link = $catdesign['category_design_icon'];
?>
<!--Single Category Item-->
<div class="single-category-item">
<img src="<?php echo $icon_link;?>" alt="<?php echo $cat_name->name;?>">
<h4> <?php echo $cat_name->name;?> </h4>
</div><!--/ Single Category Item-->
<?php endforeach; endif; ?>
</div><!--/ Category Design Area-->
<div class="mproduct-area fix">
<?php
$mproduct = new WP_Query(array(
'post_type' => 'product',
'posts_per_page'=> 10,
));
if($mproduct->have_posts()) : while($mproduct->have_posts()) : $mproduct->the_post(); ?>
<!--Single Product for Mobile Page-->
<div class="msingle-product fix">
<div class="msingle-product-image">
<a href="<?php the_permalink(); ?>">
<?php if(has_post_thumbnail( get_the_ID())){
echo get_the_post_thumbnail( get_the_ID(), 'com_product_img' );
} else {
echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
}
?></a>
</div>
<div class="mproduct-price">
<h2><strong>Price : </strong> <?php echo $product->get_price_html(); ?></h2>
</div>
<div class="mproduct-name">
<h2><?php echo esc_attr( $product->get_title() ) ?></h2>
</div>
<div class="mproduct-add-to-cart">
<?php woocommerce_template_loop_add_to_cart(); ?>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><?php the_title(); ?></h4>
</div>
<div class="modal-body">
<div class="msingle-product-image product_img_model">
<a href="<?php the_permalink(); ?>">
<?php if(has_post_thumbnail( get_the_ID())){
echo get_the_post_thumbnail( get_the_ID(), 'com_product_img' );
} else {
echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
}
?></a>
</div>
<div class="mproduct-price">
<h2><strong>Price : </strong> <?php echo $product->get_price_html(); ?></h2>
</div>
<div class="product_variable_list">
<?php wc_get_template_part('content', 'single-product'); ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Continue Shipping</button>
</div>
</div>
</div>
</div>
</div>
</div><!--/ Single Product for Mobile Page-->
<?php endwhile; endif;?>
</div>
</div>
</div>
<?php
/**
* tokoo_after_main_content hook
*
* #hooked tokoo_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'tokoo_after_main_content' );
?>
<?php get_footer(); ?>
You can watch this video for good understanding https://youtu.be/6YbYrp3ALBg
changes this script in app.js file
<script>
$('.shop-mobile-version').find('.msingle-product .button.product_type_variable.add_to_cart_button').on('click', function(){
$(this).next('.modal').modal().css('display', 'block');
//$('#myModal').modal().css('display', 'block');
return false;
});
</script>
I have a nested repeater field.
The nested part is a modal window, which when open expands on the second repeater field. But when everything is filled out the modal window displays the info from the first item in the loop.
This is how it should be working:
http://pagedev.co.uk/hoppings/product-sector.php#
Here is my code:
<div class="container">
<?php while( have_rows('product_sections') ): the_row(); ?>
<div class="sector-heading">
<img src="<?php the_sub_field('section_logo'); ?>">
<div><?php the_sub_field('section_intro'); ?></div>
</div>
<?php if( have_rows('products') ): ?>
<div class="grid-wrapper">
<?php while( have_rows('products') ): the_row(); ?>
<!--Start Single Product-->
<div class="grid-item">
<div class="image-hovers">
<img src="<?php the_sub_field('thumbnail'); ?>">
<a class="js-open-modal" href="#" data-modal-id="popup"><div class="product-hover"></div></a>
</div>
<div class="grid-title">
<h2><?php the_sub_field('product_name'); ?></h2>
</div>
</div>
<!--Start Single Product Modal-->
<div id="popup" class="modal-box">
×
<div class="modal-wrap">
<div class="modal-img">
<img src="<?php the_sub_field('thumbnail'); ?>">
</div>
<div class="modal-content">
<h2><?php the_sub_field('product_name'); ?></h2>
<p><strong><?php the_sub_field('product_size'); ?></strong></p>
<hr>
<?php the_sub_field('product_description'); ?>
<div class="modal-stockist">Find a Stockist</div>
<div class="modal-literature">Literature</div>
</div>
</div>
</div>
<!--Close Single Product Modal-->
<?php endwhile; // end of the loop. ?>
</div>
<!--End Grid Wrapper-->
<?php endif; ?>
<!-- Close product repeater field -->
<?php endwhile; // end of the loop. ?>
</div>
<!--End Container-->
Any help would be great!
Lee
I figured it out. Something so simple!
My modal window needed a unique ID for each product!
All solved :)
What I am trying to achieve is to create a grid with bootstrap inside a wordpress page and display 30 posts as thumbnails. By clicking on the thumbnail a modal box will be displayed with the image in full size.
What am I doing right now is that the modal pops up but displays the same image every time. I am trying to set the href value in the tag that will display the of the post in the modal.
<?php get_header(); ?>
<div id="content" class="clearfix">
<div id="main" class="clearfix" role="main">
<?php $counter = 0; ?>
<div class="row-fluid">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php if ($counter < 4): ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix thumbnail-post span3'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header>
<a href="#myModal" data-toggle="modal" >
<?php the_post_thumbnail( 'graphix-thumbnail' ); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
</a>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class='modal-body'>
<img src="<?php echo $url; ?>" />
</div>
</div>
<div class="page-header"><h3 itemprop="headline"><?php the_title(); ?></h3></div>
</header> <!-- end article header -->
<section class="post_content clearfix">
<?php the_content(); ?>
</section>
</article> <!-- end article -->
<?php $counter +=1; ?>
<?php else: ?>
</div>
<?php $counter = 0; ?>
<div class="row-fluid">
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
</div>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>
See this question. Its pretty easy to pass data to a modal with jQuery.
What I did wrong was that the modal's identifier was the same and the id has to be unique. So I changed the id of the modal to "#myModal-" and each one got its own unique id !