Answer the question
In order to leave comments, you need to log in
How to correctly implement links to posts in a modal window?
I'm pulling a template on WP, I ran into such a problem: the fact is that all posts open in a modal window (I use Magnific Popup). Accordingly, if I want to send a link to a specific post, nothing will come of it. in the address bar I have the root address of the site. Temporarily solved the problem using JX: I
set the parameter to links to posts rel="<?php $post->ID; ?>"
, and added the following code to the JS file:
$('.grid_item a').click(function(){
location.hash = $(this).attr('rel');
});
var required_uri = location.href;
var post_id = required_uri.split('#')[1];
if(empty(post_id) == false)
{
$.magnificPopup.open({
items: {
src: '/?p='+post_id,
type: 'ajax'
},
mainClass: 'mfp-fade',
gallery:{
enabled:true
}
});
}
function setLocation(curLoc){
try {
history.pushState(null, null, curLoc);
return;
} catch(e) {}
location.hash = '#' + curLoc;
}
<?php
$thumbnail_attributes = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
?>
<div class="single_post">
<div class="post_image">
<img src="<? echo $thumbnail_attributes[0]; ?>" />
</div>
<div class="post_header">
<h1><?php the_title(); ?></h1>
</div>
<div class="post_text">
<?php while (have_posts()): the_post();?>
<?php the_content();?>
</div>
<?php
if ( comments_open() || get_comments_number() ) : ?>
<div class="post_comment">
<?php comments_template(); ?>
</div>
<?php endif; ?>
?>
<?php endwhile; ?>
</div>
get_header()
and get_footer()
- I don’t need styles and JS in the modal window again, and if I leave them, then I have a layering of window opening events ... Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question