如何使用index.php在FrontPage上显示插件功能(内容)

时间:2015-03-07 作者:user4644682

稍微高级的Noob警报:{抱歉}。

我正在设计一个WordPress网站{尚未激活}。我有一个插件[feelbox],但目前它只显示在单个贴子页面上。插件设置中没有在frontpage[index.php]上显示它的选项。这里是主要的插件文件-feelbox。php太长,无法在此处发布。以下是第一部分:

> if (!$options) {
        feelbox_add_default_options();
    } else {
        if ($options[\'showinpostsondefault\'] == \'on\') {
            add_filter(\'the_content\', \'add_feelbox_widget_to_posts\');
        }
        if (empty($options[\'showtweetfollowup\'])) {
            $temp = array(
                \'showtweetfollowup\' => \'on\'
            );          
            update_option(\'feelbox_wp_options\', $temp);         
        }   
    }
}

function feelbox_add_default_options() {    
    $temp = array(
        \'showsparkbar\' => \'on\',
        \'showinpostsondefault\' => \'on\',
        \'showtweetfollowup\' => \'on\',
        \'validkey\' => \'0\',
        \'sortmoods\' => \'off\'
    );

    update_option(\'feelbox_wp_options\', $temp);
}

function feelbox_website_and_apikey_match() {
    $options = get_option(\'feelbox_wp_options\');
    return $options[\'validkey\'] == \'1\';
}

function feelbox_get_widget_html() {
    global $wpdb;
    global $post;
    global $moods;

    if ( ( $use_centralized_site == FALSE ) || ($use_centralized_site == TRUE && feelbox_website_and_apikey_match()) ) {
        $post_id = (int)$post->ID;
        $obj = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}lydl_posts WHERE ID=" . $post_id, ARRAY_A);
        $sum = $obj["emotion_1"]+$obj["emotion_2"]+$obj["emotion_3"]+$obj["emotion_4"]+$obj["emotion_5"]+$obj["emotion_6"];
但这是我的索引。php:

 <?php $mts_options = get_option(\'dualshock\'); ?>
<?php get_header(); ?>
<div id="page">
    <div class="content">
        <article class="article">
            <div id="content_box">
                <?php $j = 0; if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <div class="post excerpt <?php echo (++$j % 2 == 0) ? \'last\' : \'\'; ?>">
                        <header>                        
                            <h2 class="title">
                                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>
                            </h2>
                        </header><!--.header-->
                        <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail">
                            <?php if ( has_post_thumbnail() ) { ?> 
                                <?php echo \'<div class="featured-thumbnail">\'; the_post_thumbnail(\'featured\',array(\'title\' => \'\')); echo \'</div>\'; ?>
                            <?php } else { ?>
                                <div class="featured-thumbnail">
                                    <img width="450" height="200" src="<?php echo get_template_directory_uri(); ?>/images/nothumb.png" class="attachment-featured wp-post-image" alt="<?php the_title(); ?>">
                                </div>
                            <?php } ?>
                        </a>
                        <div class="post-content image-caption-format-1">
                            <?php echo excerpt(38);?>
                        </div>

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

                    <div class="post-info">

                        <span class="thecomment"><?php echo comments_number(__(\'No Comment\',\'mythemeshop\'), __(\'One Comment\',\'mythemeshop\'), \'<span class="comments">\'.__(\'Comments\',\'mythemeshop\').\'</span> <span class="comm">%</span>\');?></span>
                        <span class="readMore"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php _e(\'Read More\',\'mythemeshop\'); ?></a></span>

                    </div>
                <?php endwhile; endif; ?>   
                <span><?php if ( function_exists(\'print_feelbox_widget\') ) { print_feelbox_widget(); } ?></span>
                <!--Start Pagination-->
                <?php if ( isset($mts_options[\'mts_pagenavigation\']) == \'1\' ) { ?>
                    <?php  $additional_loop = 0; pagination($additional_loop[\'max_num_pages\']); ?>           
                <?php } else { ?>
                    <div class="pagination">
                        <ul>
                            <li class="nav-previous"><?php next_posts_link( __( \'&larr; \'.\'Older posts\', \'mythemeshop\' ) ); ?></li>
                            <li class="nav-next"><?php previous_posts_link( __( \'Newer posts\'.\' &rarr;\', \'mythemeshop\' ) ); ?></li>
                        </ul>
                    </div>
                <?php } ?>
                <!--End Pagination-->
            </div>
        </article>
        <?php get_sidebar(); ?>
<?php get_footer(); ?>
我试图通过在post info DIV下插入这个函数来调用该函数,运气不好。

<?php if ( function_exists(\'print_feelbox_widget\') ) { print_feelbox_widget(); } ?>

任何帮助都将不胜感激。谢谢

1 个回复
SO网友:Caspar

您的插件通过过滤插入其feelbox小部件the_content:

if ($options[\'showinpostsondefault\'] == \'on\') {
    add_filter(\'the_content\', \'add_feelbox_widget_to_posts\');
}
但您的索引页不显示\\u内容,只显示标题、特色缩略图、摘录和评论数。

您向我们展示的插件代码不包括print_feelbox_widget() 作用你的插件中真的存在这样的功能吗?(此外,您已将其包含在post info div的结束标记之后,并且在“循环”结束之外)(<?php endwhile; endif; ?>) 因此,如果要在“循环”中使用,则需要将其上移几行。)

否则,您可能会破解插件以过滤额外的模板标记(the_excerpt?) 然后将该标记添加到index.php 样板

因此,在插件中:

if ($options[\'showinpostsondefault\'] == \'on\') {
    add_filter(\'the_content\', \'add_feelbox_widget_to_posts\');
    add_filter(\'the_excerpt\', \'add_feelbox_widget_to_posts\');
}
然后,在index.php 类似于:

<div class="post-content image-caption-format-1">
    <?php the_excerpt();?>
</div>
当然,你必须在准确的位置上游刃有余。

祝你好运

结束

相关推荐

JQuery Plugins in Wordpress

我已经能够在某种程度上拼凑出应该如何做到这一点,但我真的很难做到这一点。我想使用Table Sorter插件(http://tablesorter.com) 在自定义页面模板中显示数据,但我不确定它是否正确。我已经钩住了“wp\\u enqueue\\u scripts”,并使用此函数将表分类器JS文件排入队列。我相信这是正确的,但是我还需要在JQuery Ready()函数中放置一行,但是我不确定如何从自定义页面模板中执行此操作。有人能解释一下吗?<?php /* Templat