有兩種可能的方式來完成你要什麼,無論是在深度在我的博客文章中描述:https://allurewebsolutions.com/open-wordpress-post-modal-without-plugin
你也可以用我的插件是:https://wordpress.org/plugins/wp-post-modal/
第一種方法
第一種方法需要修改模板,該模板服務於要在模態中顯示的內容。例如,您有一個名爲modal-content-template.php
的模板。
內部的模板,我們總結的內容我們要裝入模式與:
<?php if (!$_GET) { get_header(); } ?>
<article>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="page-title"></h1>
<section class="entry-content cf">
<?php the_content(); ?>
</section>
</article>
<?php if (!$_GET) { get_footer(); } ?>
CodePen example爲:
<?php if (!$_GET) { ?>
// content that gets loaded on mobile
<?php } ?>
當我們排除了WordPress的頁眉和頁腳模板的完整的示例JS需要做這項工作
第二種方法
第二種方法稍微優雅一些。我們使用modalContent.load(post_link + ' #modal-ready');
方法來加載模態內容。
模式聯繫人包裝在ID爲#modal-ready
的包裝容器中。這可以通過使用掛鉤到內容的函數甚至不用觸摸頁面模板來完成。
add_action('the_content', 'wrap_content');
function wrap_content($content)
{
return '<div id="modal-ready">' . $content . '</div>';
}
這聽起來像一個超級簡單的解決方案。但是,當我嘗試將其放在functions.php頁面中時,它會引發致命錯誤,並稱它調用了未定義的函數。 PHP並不是我最強烈的觀點。感謝您的幫助,diggy。 – Aganator 2013-05-03 14:04:09
你能告訴我這個錯誤究竟是什麼意思? – diggy 2013-05-03 14:13:57
致命錯誤:調用未定義的函數add_shortcode()在/nfs/c09/h04/mnt/140053/domains/adamgreener.com/html/wp-includes/functions.php上線3871 – Aganator 2013-05-03 15:09:52