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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算