个性化阅读
专注于IT技术分析

修改WordPress PHP动态内容

我的页面是bewitcheryinc.com, 我正在尝试重新排列主页。我需要用下面的文字切换促销区域(带有3个矩形的部分)。我需要先显示文本, 然后显示促销区域(带有3个矩形的部分)。我已经联系了主题支持, 他们告诉我内容是动态的, 唯一尝试的解决方案是用以下代码替换header.php。

<?php
/**
 * Displays the header content
 *
 * @package Theme Freesia
 * @subpackage Edge
 * @since Edge 1.0
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<?php
$edge_settings = edge_get_theme_options(); ?>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
<!-- Masthead ============================================= -->
<header id="masthead" class="site-header">
        <?php if ( function_exists( 'the_custom_header_markup' ) ) {
            if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) {
                echo '<div class="custom-header">
                    <div class="custom-header-media">';
                the_custom_header_markup();
                echo '</div>
                </div>';
            }else{ 
                if ( has_header_image() ) {?>
                    <a href="<?php echo esc_url(home_url('/'));?>"><img src="<?php header_image(); ?>" class="header-image" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" /> </a>
                <?php }
            }
        } else { ?>
        <a href="<?php echo esc_url(home_url('/'));?>"><img src="<?php header_image(); ?>" class="header-image" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" /> </a>
        <?php } ?>
        <div class="top-header">
            <div class="container clearfix">
                <?php
                if( is_active_sidebar( 'edge_header_info' )) {
                    dynamic_sidebar( 'edge_header_info' );
                }
                if($edge_settings['edge_top_social_icons'] == 0):
                    echo '<div class="header-social-block">';
                        do_action('social_links');
                    echo '</div>'.'<!-- end .header-social-block -->';
                endif;
                 do_action('edge_site_branding'); ?>
            </div> <!-- end .container -->
        </div> <!-- end .top-header -->
        <!-- Main Header============================================= -->
                <div id="sticky_header">
                    <div class="container clearfix">
                        <h3 class="nav-site-title">
                            <a href="<?php echo esc_url(home_url('/'));?>" title="<?php echo esc_attr(get_bloginfo('name', 'display'));?>"><?php bloginfo('name');?></a>
                        </h3>
                    <!-- end .nav-site-title -->
                        <!-- Main Nav ============================================= -->
                        <?php
                            if (has_nav_menu('primary')) { ?>
                        <?php $args = array(
                            'theme_location' => 'primary', 'container'      => '', 'items_wrap'     => '<ul id="primary-menu" class="menu nav-menu">%3$s</ul>', ); ?>
                        <nav id="site-navigation" class="main-navigation clearfix">
                            <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
                                <span class="line-one"></span>
                                <span class="line-two"></span>
                                <span class="line-three"></span>
                            </button>
                            <!-- end .menu-toggle -->
                            <?php wp_nav_menu($args);//extract the content from apperance-> nav menu ?>
                        </nav> <!-- end #site-navigation -->
                        <?php } else {// extract the content from page menu only ?>
                        <nav id="site-navigation" class="main-navigation clearfix">
                            <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
                                <span class="line-one"></span>
                                <span class="line-two"></span>
                                <span class="line-three"></span>
                            </button>
                        <!-- end .menu-toggle -->
                            <?php   wp_page_menu(array('menu_class' => 'menu', 'items_wrap'     => '<ul id="primary-menu" class="menu nav-menu">%3$s</ul>')); ?>
                        </nav> <!-- end #site-navigation -->
                        <?php }
                        $search_form = $edge_settings['edge_search_custom_header'];
                        if (1 != $search_form) { ?>
                            <div id="search-toggle" class="header-search"></div>
                            <div id="search-box" class="clearfix">
                                <?php get_search_form();?>
                            </div>  <!-- end #search-box -->
                        <?php } 

            echo '</div> <!-- end .container -->
            </div> <!-- end #sticky_header -->';
        $enable_slider = $edge_settings['edge_enable_slider'];
        edge_slider_value();
        if ($enable_slider=='frontpage'|| $enable_slider=='enitresite'){
            if(is_front_page() && ($enable_slider=='frontpage') ) {
                if($edge_settings['edge_slider_type'] == 'default_slider') {
                        edge_page_sliders();
                }else{
                    if(class_exists('Edge_Plus_Features')):
                        edge_image_sliders();
                    endif;
                }
            }
            if($enable_slider=='enitresite'){
                if($edge_settings['edge_slider_type'] == 'default_slider') {
                        edge_page_sliders();
                }else{
                    if(class_exists('Edge_Plus_Features')):
                        edge_image_sliders();
                    endif;
                }
            }
        } ?>
</header> <!-- end #masthead -->
<!-- Main Page Start ============================================= -->
<div id="content">
<div class="container clearfix">
<?php 
if(is_front_page()){
    if( have_posts() ) {
        while( have_posts() ) {
        the_post();
        get_template_part( 'content', get_post_format() );
        }
    } else { ?>
    <h2 class="entry-title"> <?php esc_html_e( 'No Posts Found.', 'edge' ); ?> </h2>
    <?php }

    do_action('edge_display_frontpage_features');
}
if(!is_home()){?>
    <div class="page-header">
        <h1 class="page-title"><?php echo edge_header_title(); ?></h1>
        <!-- .page-title -->
        <?php edge_breadcrumb(); ?>
        <!-- .breadcrumb -->
    </div>
    <!-- .page-header -->
<?php }

替换headr.php后, 必须添加以下CSS:

.home .entry-header, .home .entry-meta, section#post-417, .home .entry-footer {
display:none;
}

当我按照这些说明进行操作时, 主页将我的原始页面文本显示为博客文章, 其中包含”更多”标签以及meta标签。阅读更多链接链接回到首页。我只希望首页显示我的页面标题, 一些文本, 然后显示促销图片框。

如果有帮助, 我相信打开促销区域后, 主题将使用front-page-feature.php模板而不是索引页。吼叫。

<?php
function edge_frontpage_features(){
    $edge_settings = edge_get_theme_options();
    if($edge_settings['edge_disable_features'] != 1){
        $edge_features = '';
        $edge_total_page_no = 0; 
        $edge_list_page = array();
        for( $i = 1; $i <= $edge_settings['edge_total_features']; $i++ ){
            if( isset ( $edge_settings['edge_frontpage_features_' . $i] ) && $edge_settings['edge_frontpage_features_' . $i] > 0 ){
                $edge_total_page_no++;

                $edge_list_page =   array_merge( $edge_list_page, array( $edge_settings['edge_frontpage_features_' . $i] ) );
            }

        }
        if ( !empty( $edge_list_page ) && $edge_total_page_no > 0 ) {
            echo '<!-- Promotional Area ============================================= -->';
                $edge_features  .= '<div class="promonational-area">';
                                $get_featured_posts         = new WP_Query(array(
                                'posts_per_page'        => $edge_settings['edge_total_features'], 'post_type'             => array('page'), 'post__in'              => $edge_list_page, 'orderby'               => 'post__in', ));
                    $edge_features .= '<div class="column clearfix">';
                $j = 1;
                while ($get_featured_posts->have_posts()):$get_featured_posts->the_post();
                $attachment_id = get_post_thumbnail_id();
                $image_attributes = wp_get_attachment_image_src($attachment_id, 'pixgraphy_promotional_image');
                            $excerpt                     = get_the_excerpt();
                    $edge_features .= '<div class="three-column">';
                    if ($image_attributes) {
                        $edge_features  .= '<div class="promonational-img" title="'.the_title('', '', false).'"' .' style="background-image:url(' ."'" .esc_url($image_attributes[0])."'" .')"> <a class="promonational-link" href="'.get_the_permalink().'"></a>   ';
                        $edge_features .= '<div class="promonational-overlay">
                                <h4>'.get_the_title().'</h4></div></div>';
                    }
                    $edge_features  .='</div><!-- end .three-column -->';
                    $j++;
                    endwhile;
                    $edge_features  .='</div><!-- .end column-->';
                    $edge_features  .='</div><!-- end .promonational-area -->';
                }
        echo $edge_features;
    }
        wp_reset_postdata();
}
add_action('edge_display_frontpage_features', 'edge_frontpage_features');

有人可以帮忙吗?我显然不精通PHP / WordPress。谢谢!


#1


我认为这会起作用:

在index.php中移动

if(is_front_page()){do_action(‘edge_display_frontpage_features’); }

就在之前

get_template_part( 'pagination', 'none' );

在header.php中。

这会将首页功能放在帖子主要部分的”主要”内容之后。现在, 你需要弄清楚如何为文本添加正确的帖子内容。目前看来, 它没有获取正确的帖子类型。这可能是帖子类型中的示例帖子。

但是该文本应该是静态的还是随你最近发布的内容而变化?如果它应该是静态的, 则应进入管理控制台中的”设置”->”读取”, 并将首页设置为静态页面, 然后将文本放入该页面内容中。

赞(0)
未经允许不得转载:srcmini » 修改WordPress PHP动态内容

评论 抢沙发

评论前必须登录!