2013-05-02 29 views
1

我在一個只有三個頁面的WordPress圖庫網站上工作:主頁,圖庫和生物(http://adamgreener.com/)。莫代爾彈出窗口中的WordPress頁面內容

當您點擊Bio時,Bio內容彈出,由Easy Modal插件(在插件設置中手動輸入HTML內容)生成。

我在WordPress頁面中也有完全相同的HTML內容(移動瀏覽者看到的不是彈出窗口)。

該頁面編輯起來非常簡單,但對於普通用戶來說,模態內容並不那麼友好。我正在尋求一種方法,允許用戶只編輯生物頁面,並同時更新模式內容。

這種行爲的最佳途徑是什麼?

在此先感謝!

回答

1

您可以使用get_page來獲取頁面內容,以及在彈出窗口中顯示短代碼。在functions.php文件在您的WordPress主題,例如:

add_action('init', 'greener_shortcode_init', 11); 
function greener_shortcode_init() 
{ 
    add_shortcode('greener_bio', 'greener_bio_shortcode'); 
} 

function greener_bio_shortcode($atts) 
{ 
    $page_id = 123; // the ID of the Bio page 
    $page_data = get_page($page_id); 
    $return = ''; 
    $return .= '<h2>' . $page_data->post_title . '</h2>'; 
    $return .= $page_data->post_content; 
    return $return; 
} 

然後,在你的模式,使用簡碼:

[greener_bio]

+0

這聽起來像一個超級簡單的解決方案。但是,當我嘗試將其放在functions.php頁面中時,它會引發致命錯誤,並稱它調用了未定義的函數。 PHP並不是我最強烈的觀點。感謝您的幫助,diggy。 – Aganator 2013-05-03 14:04:09

+0

你能告訴我這個錯誤究竟是什麼意思? – diggy 2013-05-03 14:13:57

+0

致命錯誤:調用未定義的函數add_shortcode()在/nfs/c09/h04/mnt/140053/domains/adamgreener.com/html/wp-includes/functions.php上線3871 – Aganator 2013-05-03 15:09:52

0

有兩種可能的方式來完成你要什麼,無論是在深度在我的博客文章中描述: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>'; 
}