1

在我创建的博客中,当您以管理员身份查看实时站点时,每篇文章的底部都有一个编辑链接。

网站客户正在寻找一种在“blogroll”主页上拥有该编辑链接的方法,以便它出现在每个博客文章摘录的下方。

我已经在谷歌上寻找答案,但找不到任何东西。鉴于我对 Wordpress codex 条件逻辑的理解,我什至认为这是不可能的。

有人可以让我知道它是否可能以及如何解决这个问题吗?

==更新==

好的,在 Tim 的指导下,我找到了 content.php,其中正在为博客卷生成摘录逻辑。像这样插入 Tim 提出的代码:

<?php if ( true == generate_show_excerpt() ) : ?>
    <div class="entry-summary" itemprop="text">
        <?php the_excerpt(); ?>
                        <?php
                        if(is_user_logged_in() && current_user_can("edit_post", get_the_ID())){
                           edit_post_link("Edit this post");
                        }
                        ?>
    </div><!-- .entry-summary -->
<?php else : ?>
    <div class="entry-content" itemprop="text">
        <?php the_content(); ?>
        <?php
        wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', 'generate' ),
            'after'  => '</div>',
        ) );
        ?>
    </div><!-- .entry-content -->
<?php endif; ?>

只需确保它包含在 PHP 函数调用 ( ie ) 中。似乎工作的款待。

4

3 回答 3

1

鉴于我对 Wordpress codex 条件逻辑的理解,我什至认为这是不可能的。

这绝对是可能的!:)

在您的主题中,您很可能有一个home.php,archive.phpindex.php文件在您的帖子循环中运行。在该文件中,将有如下代码:

while(have_posts()): the_post();
  // lots of code here to display your post data
endwhile;

您需要直接找到放置它的位置,但该 while 循环中的某处将是您的摘录(很可能看起来像get_the_excerpt();或相似)。之后,您可以放置edit_post_link()​​函数。

包裹在一个条件中以检查用户是否已登录并有权查看帖子,这将打印出您正在寻找的“编辑帖子”链接:

if(is_user_logged_in() && current_user_can("edit_post", get_the_ID())){
  edit_post_link("Edit this post");
}

你把它放在哪里取决于你的主题和它是如何构建的,但是如果你环顾四周,希望你能找到它。如果它不适合您,请随意编辑您的问题并将其放入您尝试编辑的代码部分。

如果您将主主题与子主题一起使用,则应在主主题中查找相关代码部分,并将文件复制到子主题中以进行更改。

于 2016-05-11T11:13:05.090 回答
0

你好这是一个简单的任务

<a href="<?php get_edit_post_link($post->ID) ?>">Edit</a>

将此代码放在 if admin login 条件中,并在循环中..

于 2016-05-11T07:09:19.267 回答
0

在我使用 GeneratePress 主题的特定 Wordpress 安装中,我将此 php 代码放入我的子主题 functions.php 文件中以解决问题:

if ( ! function_exists( 'generate_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function generate_posted_on() 
{   
    $date = apply_filters( 'generate_post_date', true );
    $author = apply_filters( 'generate_post_author', true );

    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
        $time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    // If our date is enabled, show it
    if ( $date ) :
        printf( '<span class="posted-on">%1$s</span>',
            sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
                esc_url( get_permalink() ),
                esc_attr( get_the_time() ),
                $time_string
            )
        );
    endif;

    // If our author is enabled, show it
    if ( $author ) :
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span> %5$s',
                __( 'by','generatepress'),
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() ),
                edit_post_link( __( 'Edit', 'generate' ), '<span class="edit-link">', '</span>' )
            )
        );
    endif;

}
endif;

只需要重新定位编辑按钮现在出现在作者旁边的位置,我希望它位于摘录文本下方。

于 2016-05-11T09:18:26.850 回答