【问题标题】:Edit a custom page in wordpress在 wordpress 中编辑自定义页面
【发布时间】:2015-05-25 10:38:38
【问题描述】:

我正在使用 wordpress 主题。默认主页是最新帖子。在我的主题中,它的 home.php 是默认主页的内容。现在我想要一个静态主页和博客页面。我创建了一个名为“主页”的新页面并将其设置为主页。所以以前的默认主页内容不会出现在我的新主页中。 我的问题是如何将这些默认主页内容添加到这个新主页?我不想更改 page.php 模板,因为它会更改所有页面。我想更改这个特定的“主页”页面并将其设置为具有以前默认主页内容的主页。 有人可以帮我吗?

这是默认主页代码

<?php get_header(); ?>
<?php if ( get_option('modest_quote') == 'on' ) { ?>
    <div id="quote">
        <p id="quote-1"><span class="tagline-quote">&ldquo;</span><?php echo get_option('modest_quote_one'); ?><span class="tagline-quote">&rdquo;</span></p>
        <p id="quote-2"><?php echo get_option('modest_quote_two'); ?></p>
    </div> <!-- end #quote -->
<?php } ?>

<?php if ( get_option('modest_featured') == 'on' ) get_template_part('includes/featured'); ?>

<?php if ( get_option('modest_blog_style') == 'false' ){ ?>
    <div id="blurbs" class="clearfix">
        <?php 
            $blurbs_number = get_option('modest_use_third_page') == 'on' ? 3 : 2;
            if ( get_option('modest_use_third_page') == 'on' ) $blurbs_number = 3; 
        ?>
        <?php for ($i=1; $i <= $blurbs_number; $i++) { ?>
            <?php query_posts('page_id=' . get_pageId(html_entity_decode(get_option('modest_home_page_'.$i)))); while (have_posts()) : the_post(); ?>
                <?php 
                    global $more; $more = 0;
                ?>
                <div class="blurb<?php if ( $i == 3 ) echo ' last'; ?>">
                    <h3 class="title"><?php the_title(); ?></h3>
                    <?php the_content(''); ?>
                </div> <!-- end .blurb -->
            <?php endwhile; wp_reset_query(); ?>
        <?php } ?>

        <?php if ( $blurbs_number == 2 ) { ?>
            <div class="blurb last">
                <h3 class="title"><?php esc_html_e('Examples of Our Work','Modest'); ?></h3>
                <?php query_posts("showposts=".get_option('modest_work_number')."&cat=".get_cat_ID(get_option('modest_work_cat')));
                    if (have_posts()) : while (have_posts()) : the_post(); ?>
                        <?php 
                        $width = 56;
                        $height = 56;
                        $titletext = get_the_title();

                        $thumbnail = get_thumbnail($width,$height,'item-image',$titletext,$titletext,true,'Work');
                        $thumb = $thumbnail["thumb"];
                        $fancybox_title = get_post_meta($post->ID,'Customtitle',true) ? get_post_meta($post->ID,'Customtitle',true) : get_the_title(); ?>
                        <div class="thumb">
                            <a rel="gallery" title="<?php echo esc_attr($fancybox_title); ?>" href="<?php echo esc_attr($thumbnail['fullpath']); ?>" class="fancybox">
                                <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'item-image'); ?>
                                <span class="overlay"></span>
                                <span class="zoom-icon"></span>
                            </a>
                        </div>  <!-- end .thumb -->
                    <?php 
                    endwhile; endif; 
                wp_reset_query(); ?>
            </div> <!-- end .blurb -->
        <?php } ?>
    </div> <!-- end #blurbs -->
<?php } else { ?>
    <div id="left-area">
        <?php get_template_part('includes/entry','home'); ?>
    </div>  <!-- end #left-area -->
    <?php get_sidebar(); ?>
<?php } ?>

【问题讨论】:

  • 你能添加一些你的新模板的代码吗?
  • 我已添加代码
  • 如果您只想更改“主页”页面的名称,即“index.php”,也许.htaccess 中的一个Directoryindex 指令就可以了。

标签: wordpress


【解决方案1】:

请尝试它会给你答案

请制作主页模板并从管理面板为该页面分配模板,并请在您创建的新模板页面顶部放置以下代码

/*
Template Name: Home Page
The template for displaying Home
 */

选择您在管理面板中创建的 wordpress 页面中的主页模板

【讨论】:

    【解决方案2】:

    您可以为单独的主页设计创建主页模板。 请参考以下链接了解如何在 WordPress 中制作模板。

    https://codex.wordpress.org/Page_Templates

    然后在管理面板的主页编辑模式中请选择模板。

    用于获取内容、特色图片和所有您可以使用的有用功能,如下所列。

    the_content();
    get_the_post_thumbnail();
    get_permalink();
    get_excerpt()
    

    等等。 请 html 在模板中保持不变,只需将 php 代码放在您想要的图像内容等位置。

    【讨论】:

      【解决方案3】:

      为此任务创建并使用front-page.php 模板文件!只需将 home.php 的代码转储到 front-page.php 中即可。

      如果存在,则使用站点的front-page.php模板文件 无论是“设置”>“阅读”->“首页”,首页 显示'设置为“静态页面”或“您的最新帖子”主题 将需要考虑这两个选项,以便网站首页 将显示静态页面或博客文章索引。

      看看这个官方的 WordPress 文档https://codex.wordpress.org/Creating_a_Static_Front_Page

      【讨论】:

        猜你喜欢
        • 2019-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-31
        相关资源
        最近更新 更多