【问题标题】:Add Content to wordpress page template将内容添加到 wordpress 页面模板
【发布时间】:2023-03-08 17:35:01
【问题描述】:

我想向自定义 wordpress 页面模板添加内容,以便每个新帖子都填充相同的信息。

我使用短代码(可视化作曲家插件)创建了一个页面设计,它生成了一个页面设计,我基本上想使用自定义模板预先填充它,例如:single-release.php...

页面模板:

   <?php
/*
** page.php
** mk_build_main_wrapper : builds the main divisions that contains the content. Located in framework/helpers/global.php
** mk_get_view gets the parts of the pages, modules and components. Function located in framework/helpers/global.php
*/

get_header();


Mk_Static_Files::addAssets('mk_button'); 
Mk_Static_Files::addAssets('mk_audio');
Mk_Static_Files::addAssets('mk_swipe_slideshow');

mk_build_main_wrapper( mk_get_view('singular', 'wp-page', true) );

get_footer();

我希望预填充的内容:

[mk_page_section bg_color="#202020" attachment="fixed" bg_position="center top" bg_repeat="no-repeat" bg_stretch="true" js_vertical_centered="true" padding_top="70" padding_bottom="30" sidebar="sidebar-1"][vc_column width="1/3"][vc_single_image source="featured_image" img_size="large"][/vc_column][vc_column width="2/3"][vc_row_inner][vc_column_inner width="1/2"][vc_column_text el_class="t"]ARTIST[/vc_column_text][mk_custom_sidebar el_class="title" sidebar="sidebar-19"][vc_column_text el_class="trackname"]RELEASE: [acf field="track_name"][/vc_column_text][vc_column_text margin_bottom="30" el_class="date"]RELEASE DATE: [acf field="release_date"][/vc_column_text][vc_column_text el_class="date"]TRACKS[/vc_column_text][vc_column_text el_class="track"]01. [acf field="track_01"][/vc_column_text][vc_column_text el_class="track"]02. [acf field="track_02"][/vc_column_text][vc_column_text el_class="track"]04. [acf field="track_03"][/vc_column_text][vc_column_text el_class="track"]03. [acf field="track_04"][/vc_column_text][vc_column_text el_class="track"]05. [acf field="track_05"][/vc_column_text][mk_padding_divider size="20"][/vc_column_inner][vc_column_inner el_class="columnbuttons" width="1/2"][vc_column_text el_class="trackname"]PURCHASE:[/vc_column_text][mk_custom_sidebar el_class="buybutton" sidebar="sidebar-18"][vc_column_text el_class="trackname"]LISTEN[/vc_column_text][vc_column_text el_class="track"][acf field="audio_embed"][/vc_column_text][/vc_column_inner][/vc_row_inner][/vc_column][/mk_page_section][mk_page_section bg_color="#303030" padding_top="40" padding_bottom="40" sidebar="sidebar-1"][vc_column][mk_fancy_title color="#f2f2f2" size="20" font_weight="300" txt_transform="uppercase" margin_bottom="0" font_family="none"]NEW RELEASES[/mk_fancy_title][ess_grid alias="Single-page-releases"][/vc_column][/mk_page_section]

这可能吗? / 我该怎么做?

感谢您的帮助。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果您想更改主题的页面模板,您必须编辑位于themes/yourtheme/views/singular/wp-page.php 中的文件。

    您尝试编辑的文件只是访问 global.php 文件中的一个函数,然后该函数将加载页面的特定文件。

    顺便说一句。您可以使用

    在 php 中执行短代码
    <?php echo do_shortcode("[SHORTCODE_EXAMPLE]"); ?>
    

    【讨论】:

      【解决方案2】:

      如果 mk_page_section 是您自己创建的短代码,则需要编写一个函数来执行此操作。

      您可以创建自己的短代码,也可以使用 Visual composer 添加自己的短代码。 Google 如何将您的简码集成到使用 php 类扩展的 VC 中。

      无论哪种方式,您都必须使用 add_shortcode 函数向 WordPress 注册您的简码。

      一个示例短代码是。

      在你的functions.php中你可以添加一个短代码。

      add_shortcode('my-magic-shortcode','myCustomFunction');
      function myCustomFunction($atts){
          global $post;
          /// note these defaults can be overridden
          $atts = shortcode_atts(
              array(
                  'bg_color' => '#fff',
                  'attachment' =>  'fixed',
                  'bg_position' => 'center top',
                  'bg_stretch' => 'contain',
                  ///// add more defaults
              ), $atts, 'my-magic-shortcode');
      
         echo '<div style="background-color:'.$atts['bg_color'].';background-attachment:'.$atts['attachment'].';background-position:'.$atts['bg_position'].';background-stretch:'.$atts['bg_stretch'].';" >'.wpautop($post->post_content).'</div>';
         //// alternatively you could use a return to send all this back to a variable for use later in your page
         //// just comment out the line that echos the string above
         $str_html = '<div style="background-color:'.$atts['bg_color'].';background-attachment:'.$atts['attachment'].';background-position:'.$atts['bg_position'].';background-stretch:'.$atts['bg_stretch'].';" >'.wpautop($post->post_content).'</div>';
         return $str_html;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-08
        • 1970-01-01
        相关资源
        最近更新 更多