更改WordPress粘性类名称

时间:2016-02-20 07:39:37

标签: wordpress zurb-foundation

不幸的是,Foundation和WordPress都使用“粘性”类。为了避免这种情况,我总是使用一个小功能,将类更改为WordPress的'wp-sticky'。但是,该功能现在似乎将该类应用于每个帖子(包括非粘贴帖子)。

ALTER TRIGGER [dbo].[u_filepath] 
ON [FileDB].[dbo].[FT] 
FOR UPDATE
AS
    -- create a CTE to get the primary key, old and new path names
    WITH UpdatedPaths AS
    (
        SELECT
            i.PrimaryKey,
            OldPathName = d.file_stream.pathname(),
            NewPathName = i.file_stream.pathname()
        FROM 
            Inserted i
        INNER JOIN
            Deleted d ON i.PrimaryKey = d.PrimaryKey
    )
    -- update the "AT" table where the old and new path names don't match
    UPDATE dbo.AT
    SET [Path] = up.NewPathName
    FROM UpdatedPaths up
    WHERE
       up.OldPathName <> up.NewPathName
       dbo.AT.PrimaryKey = up.PrimaryKey
GO

关于如何更改粘性类名称的任何想法(并不适用于所有帖子)?

编辑:它会在粘贴帖子上用'wp-sticky'替换'sticky',但是,它也会将其添加到非粘性的帖子中。

1 个答案:

答案 0 :(得分:1)

它可能从来没有像它本来应该的那样起作用。问题是在将'sticky'添加到数组之前,没有条件检查$classes数组中是否'wp-sticky'

function remove_sticky_class( $classes ) {
    if ( in_array( 'sticky', $classes, true ) ) {
        $classes = array_diff($classes, array('sticky'));
        $classes[] = 'wp-sticky';
    }
    return $classes;
}
add_filter( 'post_class', 'remove_sticky_class' );