Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;“不包括当前职位”;小部件wordpress(PHP帮助)_Php_Wordpress_Widget - Fatal编程技术网

&引用;“不包括当前职位”;小部件wordpress(PHP帮助)

&引用;“不包括当前职位”;小部件wordpress(PHP帮助),php,wordpress,widget,Php,Wordpress,Widget,您好:)我正在我的网站上使用“灵活的帖子小部件”来显示相关内容或我感兴趣的内容,显示在侧边栏上 这个小部件工作得很好,我对继续使用它很感兴趣,特别是对于我的站点的设计和适应性选项 问题?它不包含“排除当前帖子”的功能 我正在查看代码(我将其添加到这个线程中),我想我可以为这个函数添加一些代码行(排除我正在阅读的帖子) 不幸的是,我是编程新手,我不知道该在哪里添加什么 你能帮我吗 <?php /** * Flexible Posts Widget: Default widget templ

您好:)我正在我的网站上使用“灵活的帖子小部件”来显示相关内容或我感兴趣的内容,显示在侧边栏上

这个小部件工作得很好,我对继续使用它很感兴趣,特别是对于我的站点的设计和适应性选项

问题?它不包含“排除当前帖子”的功能

我正在查看代码(我将其添加到这个线程中),我想我可以为这个函数添加一些代码行(排除我正在阅读的帖子)

不幸的是,我是编程新手,我不知道该在哪里添加什么

你能帮我吗

<?php
/**
 * Flexible Posts Widget: Default widget template
 * 
 * @since 3.4.0
 *
 * This template was added to overcome some often-requested changes
 * to the old default template (widget.php).
 */

// Block direct requests
if ( !defined('ABSPATH') )
    die('-1');

echo $before_widget;

if ( ! empty( $title ) )
    echo $before_title . $title . $after_title;

if ( $flexible_posts->have_posts() ):

function be_exclude_current_post( $args ) {
        if( is_singular() && !isset( $args['post__in'] ) )
            $args['post__not_in'] = array( get_the_ID() );
        return $args;
    }
    add_filter( 'widget_posts_args', 'be_exclude_current_post' );

?>
    <ul class="dpe-flexible-posts">
    <?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
        <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php echo the_permalink(); ?>">
                <?php
                    if ( $thumbnail == true ) {
                        // If the post has a feature image, show it
                        if ( has_post_thumbnail() ) {
                            the_post_thumbnail( $thumbsize );
                        // Else if the post has a mime type that starts with "image/" then show the image directly.
                        } elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
                            echo wp_get_attachment_image( $post->ID, $thumbsize );
                        }
                    }
                ?>
                <div class="title"><?php the_title(); ?></div>
            </a>
        </li>
<hr>
    <?php endwhile; ?>
    </ul><!-- .dpe-flexible-posts -->
<?php   
endif; // End have_posts()

echo $after_widget;


    将其添加到主题的“functions.php”中,并将其从小部件模板中删除

    function be_exclude_current_post( $args ) {
        if( is_singular() && !isset( $args['post__in'] ) )
            $args['post__not_in'] = array( get_the_ID() );
        return $args;
    }
    add_filter( 'dpe_fpw_args', 'be_exclude_current_post' );