【问题标题】:Need help making changes to pre-made blog post formats from custom WP Theme需要帮助从自定义 WP 主题更改预制的博客文章格式
【发布时间】:2013-09-30 12:38:12
【问题描述】:

我从 Codestag 的 Themeforest 购买了一个名为 Shift 的 WP 主题,它是一个非常易于使用和干净的 UI。它主要用于博客风格的帖子,他们已经创建了预制的博客帖子风格......

例如,“音频”帖子是文本和嵌入的音频文件。 “视频”是视频链接和文字,“照片”显然是照片和文字。

我的问题是这些无法自定义,而且我创建的博客文章类型是音频或视频,并包含艺术家的照片或专辑封面。我需要添加什么代码才能让这个预制帖子包含照片? (代码如下)

我的第二个问题是如何将顺序从音频文件、标题、文本更改为标题、照片文本和音频?

这是预制博客样式的代码:“音频”

<div class="hentry-inner">

  <div class="entry-wrapper grids">

<?php get_template_part('content', 'meta'); ?>

<div class="entry-content grid-10 clearfix">

  <?php
  $embed = get_post_meta(get_the_ID(), '_stag_audio_embed', true);

  if(!empty($embed)){
    echo do_shortcode(htmlspecialchars_decode($embed));
  }else{
    stag_audio_player(get_the_ID());
  }

  ?>

  <?php if( is_single() ) { ?>

    <h1 class="entry-title"><?php the_title(); ?></h1>

  <?php } else { ?>

    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'stag'), get_the_title()); ?>"> <?php the_title(); ?></a></h2>
  <?php } ?>

  <?php

    if(!is_singular()){
      if(get_the_excerpt() != '') echo "<p>".strip_shortcodes(get_the_excerpt())."</p>";
    }else{
      the_content(__('Continue Reading', 'stag'));
      wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'stag').'</strong> ',   'after' => '</p>', 'next_or_number' => 'number'));
    }

  ?>
</div>
 <span class="bottom-accent"></span>
  </div>
</div>

非常感谢您的帮助! -彼得

【问题讨论】:

    标签: wordpress post formatting format blogs


    【解决方案1】:

    这里我添加了the_post_thumbnail(见Codex)以在内容上方显示一张照片:

    <div class="hentry-inner">
    
        <div class="entry-wrapper grids">
    
            <?php get_template_part('content', 'meta'); ?>
    
            <div class="entry-content grid-10 clearfix">
    
                <?php
                $embed = get_post_meta(get_the_ID(), '_stag_audio_embed', true);
    
                if(!empty($embed)){
                    echo do_shortcode(htmlspecialchars_decode($embed));
                }else{
                    stag_audio_player(get_the_ID());
                }
    
                ?>
    
                <?php if( is_single() ) { ?>
    
                <h1 class="entry-title"><?php the_title(); ?></h1>
    
                <?php } else { ?>
    
                <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'stag'), get_the_title()); ?>"> <?php the_title(); ?></a></h2>
                <?php } ?>
    
                <?php
    
                if(!is_singular()){
                    if(get_the_excerpt() != '') echo "<p>".strip_shortcodes(get_the_excerpt())."</p>";
                }else{
    
                    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                        the_post_thumbnail();
                    } 
    
                    the_content(__('Continue Reading', 'stag'));
    
                    wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'stag').'</strong> ',   'after' => '</p>', 'next_or_number' => 'number'));
                }
    
                ?>
            </div>
            <span class="bottom-accent"></span>
        </div>
    </div>
    

    此模板显示标题、特色图片、内容、音频(按此顺序):

    <div class="hentry-inner">
    
        <div class="entry-wrapper grids">
    
            <?php get_template_part('content', 'meta'); ?>
    
            <div class="entry-content grid-10 clearfix">
    
                <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'stag'), get_the_title()); ?>"> <?php the_title(); ?></a></h2>
    
                <?php
    
                if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                    the_post_thumbnail();
                }
    
                the_content(__('Continue Reading', 'stag'));
    
                wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'stag').'</strong> ',   'after' => '</p>', 'next_or_number' => 'number'));
    
                $embed = get_post_meta(get_the_ID(), '_stag_audio_embed', true);
    
                if(!empty($embed)){
                    echo do_shortcode(htmlspecialchars_decode($embed));
                }else{
                    stag_audio_player(get_the_ID());
                }
    
                ?>
    
            </div>
            <span class="bottom-accent"></span>
        </div>
    </div>
    

    WordPress 有很好的文档记录,我建议您深入了解WordPress Codex。如果您需要进一步的自定义,您可能应该要求和/或聘请主题作者为您进行修改。

    【讨论】:

    • 非常感谢!对于第二组代码,您可以在其中包含允许照片吗?所以如果是标题>照片>文本>音频?那太棒了!再次感谢您的帮助!
    • 更新了代码。如果它解决了您的问题,请不要忘记批准我的回答。 ;)
    • 这太完美了!最后一个问题/问题...此序列仅在我单击博客文章并将我带到文章页面时出现。有什么方法可以在主博客卷/网站上显示该序列?
    • 谢谢!不幸的是,我的代表太低了,无法聊天。还有其他形式的com吗?
    猜你喜欢
    • 2013-10-13
    • 2013-02-15
    • 2015-10-05
    • 2018-03-19
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多