douzhun5971 2017-02-10 13:22
浏览 62
已采纳

Wordpress:移动条目标题

There has been something that i can't seem to work out. I's about an entry title, which on the front page shows on top of each portfolio item (on hover).

Here you can see what i mean; www.untoldworks.com

All i'm trying to do is move the entry title so it shows in line with the entry category & entry date on the left side of the portfolio item.

As i understand the entry meta layout for the portfolio page is found within template-tags.php

function eris_entry_header() {

if ( !is_single() && ( !is_search() && ( 'link' == get_post_format() || 'quote' == get_post_format() ) ) ) {
    return;
}

$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';

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

$edit_post_link = '';

if ( is_user_logged_in() ) {
    $edit_post_link = '<a href="' . esc_url( get_edit_post_link() ) . '"></a>';
}

$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() )
);

$posted_on = sprintf(
    esc_html_x( '%s', 'post date', 'eris' ),
    '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);

if ( 'portfolio' == get_post_type() ) {
    $categories_list = get_the_term_list( get_the_ID(), 'ct_portfolio', '', '&nbsp;', '' );
} else {
    $categories_list = get_the_term_list( get_the_ID(), 'category', '', '&nbsp;', '' );
}

if ( is_single() ) {
    the_title( '<h1 class="entry-title">', '</h1>' );
} else {
    the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}

printf( '<div class="entry-meta"><span class="category-list">%1$s</span><span class="post-date">%2$s</span><span class="edit-link">%3$s</span></div>', $categories_list, $posted_on, $edit_post_link );}

It would be great if the entry title would show first (so left bottom corner of portfolio item) after that the entry category and after that the date.

Hope someone can figure this out XD Thanks in advance!

  • 写回答

1条回答 默认 最新

  • douji6940 2017-02-10 13:53
    关注

    Answer / Final Update:

    From the code you posted, it seems that the last line is the relevant one:

    printf( '<div class="entry-meta"><span class="category-list">%1$s</span><span class="post-date">%2$s</span><span class="edit-link">%3$s</span></div>', $categories_list, $posted_on, $edit_post_link );}
    

    You will need to add a new argument and use argument swapping. Try replacing this line with this:

    // use 'get_the_title()' instead of 'the_title()'
    $my_title = get_the_title();
    
    // note that I added the "$my_title" to the arguments on the end of the line
    // and also that I added "%4$s" to the printf() function to show our new title
    printf( '<div class="entry-meta">%4$s<span class="category-list">%1$s</span><span class="post-date">%2$s</span><span class="edit-link">%3$s</span></div>', $categories_list, $posted_on, $edit_post_link, $my_title );}
    

    You can find more info and explanation regarding printf() on the official codex page here.

    For a better explaination look at this example:

    $city = 'New York';
    $zipcode = '12345';
    
    printf( 'Your city is %1$s, and your zip code is %2$s.', $city, $zipcode );
    

    will become:

    "Your city is New York, and your zip code is 12345."


    Update: (before using get_the_title() )

    I can see in your sourcecode that the new element with the title is added on the wrong place, right before the entry-meta container.

    In the source code you see this:

    <span class="post-date">Stefan Rustenburg</span> // this is our post-title
    <div class="entry-meta">
        <span class="post-date"></span> // this seems to be an empty element ?!
        <span class="category-list"></span>
        <span class="post-date"></span>
        <span class="edit-link"></span>
    </div>
    

    If I change the code to this:

    <div class="entry-meta">
        <span class="post-date">Stefan Rustenburg</span> // this is our post-title
        <span class="post-date"></span> // this seems to be an empty element ?!
        <span class="category-list"></span>
        <span class="post-date"></span>
        <span class="edit-link"></span>
    </div>
    

    The title get added to the right place. See: post-title on right place

    Did you create the span element with the class post-date yourself? How is your printf() function currently looking?

    P.S. Maybe also try using the_title() without before and after, to see if that change something.

    As you are using printf() maybe you need to use get_the_title() instead of the_title().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看