wordpress投稿の投稿タイプで作成したページ 本文でモーダルウィンドウを実装したい

wordpress投稿の投稿タイプで作成したページ
本文でモーダルウィンドウを実装したい
モーダルの内容は
カスタムフィールド
フィールド名:modal
に格納されたhtml

モーダル用のhtmlには
アンカーとして
id:rule01~rule011

投稿タイプ本文内のテキストリンクから
各アンカーに移動できるようにしたい

 

To implement the modal window in your WordPress post types using content stored in the custom field “modal” and allow text links to anchor to specific points within the modal, follow these steps:

1. Create the Modal Structure:

First, create the HTML structure for the modal window. Add this structure to the single post template where the custom post type content is displayed (e.g., single-{post_type}.php).

single.phpに下記コード追加

<?php
// Fetch the modal content from the custom field
$modal_content = get_post_meta(get_the_ID(), 'modal', true);
if ($modal_content):
?>
<div id="customModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<?php echo $modal_content; // Output the modal content ?>
</div>
</div>
<?php endif; ?>

2. Add Text Links in the Post Content:

In your post content, add the text links that will trigger the modal and navigate to specific anchor points within it.

Example of how you can add text links to the post content:

テキストリンクの例

<a href="#rule01" class="open-modal">Go to Rule 01</a>
<a href="#rule02" class="open-modal">Go to Rule 02</a>
<!-- Repeat for other anchors -->

3. JavaScript for Modal Behavior:

To ensure the modal opens when a link is clicked and navigates to the corresponding anchor inside the modal, add the following JavaScript to your theme’s footer.php or enqueue it properly via the functions.php:

 

single.phpで
カスタムフィールドフィールド名:modal がある場合のみ呼び出すことにしました。
(if ($modal_content): 内)

document.addEventListener('DOMContentLoaded', function() {
// Get the modal
var modal = document.getElementById('customModal');

// Get the close button
var span = document.querySelector('.close');

// Open the modal when a link is clicked
document.querySelectorAll('.open-modal').forEach(function(link) {
link.addEventListener('click', function(e) {
e.preventDefault();
var anchor = this.getAttribute('href'); // Get anchor from link

// Open the modal
modal.style.display = 'block';

// Scroll to the specific anchor inside the modal
var target = document.querySelector(anchor);
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
}
});
});

// Close the modal when the user clicks on <span> (x)
span.onclick = function() {
modal.style.display = 'none';
}

// Close the modal when the user clicks anywhere outside of it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
});

 

4. CSS for Modal Styling:

Add the required CSS to style the modal window. Here’s an example:

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-height: 80%;
overflow-y: auto;
}

/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}

コメント

“wordpress投稿の投稿タイプで作成したページ 本文でモーダルウィンドウを実装したい” への12件のフィードバック

  1. Interesting read! Data-driven insights are key to smart betting, and platforms like jiliaaa game seem to prioritize that with their analytics. Understanding player patterns is huge – good stuff!

  2. As a betting enthusiast, I appreciate platforms like Jili OK that blend strategy with fun-especially with their AI-driven insights and diverse game library. A fresh take on online gaming!

  3. Interesting points about bankroll management! Seeing platforms like jljl9 slot prioritize easy deposits via GCash & PayMaya is smart for the Philippines market – accessibility is key! Good read.

  4. Really interesting read! Seeing platforms like juan 365 slot prioritize easy sign-up (like with GCash!) & 24/7 access is a game changer for Filipino players. Makes it so much more accessible!

  5. Interesting points about maximizing returns! Thinking about platforms like ph11 app casino, solid security & quick deposits are key for a smooth experience. Definitely impacts strategy!

  6. Keno’s randomness is fascinating! Understanding probability helps, but it’s still a game of chance. Easy access via platforms like the bossjili app download apk makes enjoying games convenient, with secure deposits & diverse options. Fun to explore!

  7. Solid analysis! Seeing more platforms like BossJili prioritizing secure, regulated play in the Philippines is great. Easy deposits via GCash & a wide game selection – check out their bossjili login for options! Betting feels safer with PAGCOR licensing.

  8. It’s crucial to verify any new platform’s security-KYC compliance is a must for protecting your funds. Seeing platforms like bet100 app login focus on that for Filipino players is a good sign, alongside responsible gaming features. Stay vigilant!

  9. Solid analysis! Understanding variance is key in tournaments. Seeing platforms like bet100 app link adapt to local preferences (like Filipino-focused games) is smart – caters to player habits & boosts engagement. Good stuff!

  10. Interesting read! It’s smart how platforms like legend link game are focusing on localized payment options like Maya – makes things so much easier for players here. Casual gaming is all about convenience, right?

  11. It’s so important to remember gaming should be fun, not a source of stress. Seeing platforms like legend link ph prioritize secure, easy deposits (even with options like Maya!) is a good sign. Enjoy responsibly!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA