doushou6480 2016-09-17 20:32
浏览 25
已采纳

如何将帖子格式添加到主题?

For classipress theme. I can register post_formats the normal way in functions (works - I can select "link" type in the editor), but I can't figure out how to get it to actually use a template file for link posts.

I have used the get_template_part('content', get_post_format()); in the past successfully,

but I can't figure how to inject that into the single.php's code for this theme:

Single.php

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package ClassiPress\Templates
 * @author  AppThemes
 * @since   ClassiPress 1.0
 */
?>


<div class="content">

    <div class="content_botbg">

        <div class="content_res">

            <div id="breadcrumb"><?php cp_breadcrumb(); ?></div>

            <div class="content_left">

                <?php appthemes_before_blog_loop(); ?>

                <?php if ( have_posts() ) : ?>

                    <?php while ( have_posts() ) : the_post(); ?>


                        <?php appthemes_before_blog_post(); ?>

                        <?php appthemes_stats_update( $post->ID ); //records the page hit ?>

                        <div class="shadowblock_out">

                            <div class="shadowblock">

                                <div class="post">




                                    <?php appthemes_before_blog_post_title(); ?>




                                    <h1 class="single blog"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

                                    <?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>

                                    <?php appthemes_before_blog_post_content(); ?>

                                    <?php if ( has_post_thumbnail() ): ?>

                                        <div id="main-pic">
                                            <?php cp_get_blog_image_url(); ?>
                                        </div>

                                    <?php endif; ?>

                                    <?php the_content(); ?>




                                    <div class="dotted"></div>
                                    <div class="pad5"></div>

                                    <?php appthemes_after_blog_post_content(); ?>



                                </div><!-- .post -->

                            </div><!-- .shadowblock -->

                        </div><!-- .shadowblock_out -->

                        <?php appthemes_after_blog_post(); ?>

                    <?php endwhile; ?>

                    <?php appthemes_after_blog_endwhile(); ?>

                <?php else: ?>

                    <?php appthemes_blog_loop_else(); ?>

                <?php endif; ?>

                <div class="clr"></div>

                <?php appthemes_after_blog_loop(); ?>

                <div class="clr"></div>

                <?php comments_template(); ?>


            </div><!-- .content_left -->

            <?php get_sidebar( 'blog' ); ?>

            <div class="clr"></div>

        </div><!-- .content_res -->

    </div><!-- .content_botbg -->

</div><!-- .content -->

Content.php

<?php
/**
 * Post loop content template.
 *
 * @package ClassiPress\Templates
 * @author  AppThemes
 * @since   ClassiPress 3.4
 */
?>

<div <?php post_class( 'shadowblock_out' ); ?> id="post-<?php the_ID(); ?>">

    <div class="shadowblock">

        <?php appthemes_before_blog_post_title(); ?>

        <h3 class="loop"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>

        <?php appthemes_after_blog_post_title(); ?>

        <?php appthemes_before_blog_post_content(); ?>

        <div class="entry-content">

            <?php if ( has_post_thumbnail() ) the_post_thumbnail( 'blog-thumbnail' ); ?>

            <?php the_content( __( 'Continue reading ...', APP_TD ) ); ?>

        </div>

        <?php appthemes_after_blog_post_content(); ?>

    </div><!-- #shadowblock -->

</div><!-- #shadowblock_out -->

Tried a lot of things, unsuccessful in doing anything but breaking the page.

Thanks

  • 写回答

1条回答 默认 最新

  • dsjhejw3232 2016-09-17 21:14
    关注

    Post formats are used to customize the presentation of post items. If you check out some theme that supports post formats (For example Twenty Fifteen), you will see that the single.php file is not used to output the contents of the post - which is delegated to content-*.php files. (For example, the the_content() function, which outputs a post's content is not in single.php, but in content.php (and content-link.php and others).

    Your single.php does not seem to be built this way, so it does not support post formats, but it can be refactored easily, just split it into two files (in single.php you should keep the "frame" code that is common for every post format, then move the rest into a new content.php file, which will be used as the default format):

    single.php

    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package ClassiPress\Templates
     * @author  AppThemes
     * @since   ClassiPress 1.0
     */
    ?>
    
    
    <div class="content">
    
        <div class="content_botbg">
    
            <div class="content_res">
    
                <div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
    
                <div class="content_left">
    
                    <?php appthemes_before_blog_loop(); ?>
    
                    <?php if ( have_posts() ) : ?>
    
                        <?php while ( have_posts() ) : the_post(); ?>
    
    
                            <?php appthemes_before_blog_post(); ?>
    
                            <?php appthemes_stats_update( $post->ID ); //records the page hit ?>
    
                            <?php
                                // Note the below line which loads the desired content*.php
                                get_template_part('content', get_post_format()); 
                            ?>
    
                            <?php appthemes_after_blog_post(); ?>
    
                        <?php endwhile; ?>
    
                        <?php appthemes_after_blog_endwhile(); ?>
    
                    <?php else: ?>
    
                        <?php appthemes_blog_loop_else(); ?>
    
                    <?php endif; ?>
    
                    <div class="clr"></div>
    
                    <?php appthemes_after_blog_loop(); ?>
    
                    <div class="clr"></div>
    
                    <?php comments_template(); ?>
    
    
                </div><!-- .content_left -->
    
                <?php get_sidebar( 'blog' ); ?>
    
                <div class="clr"></div>
    
            </div><!-- .content_res -->
    
        </div><!-- .content_botbg -->
    
    </div><!-- .content -->
    

    content.php

                            <div class="shadowblock_out">
    
                                <div class="shadowblock">
    
                                    <div class="post">
    
    
    
    
                                        <?php appthemes_before_blog_post_title(); ?>
    
    
    
    
                                        <h1 class="single blog"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    
                                        <?php appthemes_after_blog_post_title(); ?>
    <div style="margin-top:10px; text-align:center;">
    <?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
    </div>
    
                                        <?php appthemes_before_blog_post_content(); ?>
    
                                        <?php if ( has_post_thumbnail() ): ?>
    
                                            <div id="main-pic">
                                                <?php cp_get_blog_image_url(); ?>
                                            </div>
    
                                        <?php endif; ?>
    
                                        <?php the_content(); ?>
    
    
    
    
                                        <div class="dotted"></div>
                                        <div class="pad5"></div>
    
                                        <?php appthemes_after_blog_post_content(); ?>
    
    
    
                                    </div><!-- .post -->
    
                                </div><!-- .shadowblock -->
    
                            </div><!-- .shadowblock_out -->
    

    Now, for additional post formats, for example gallery, you will have to create a file named content-gallery.php and implement it. You can derive it from the default content.php, but you decide how it should look like.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题