2017-02-10 96 views
1

有一些我似乎無法解決的問題。我是關於一個條目標題,它在首頁顯示在每個投資組合項目上(懸停)。WordPress的:移動標題

在這裏你可以看到我的意思; www.untoldworks.com

我所要做的就是移動條目標題,使其顯示符合投資組合項目左側的條目類別&。

據我瞭解的投資組合頁面的條目元佈局模板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);} 

這將是巨大的,如果條目標題將顯示第一(組合項目所以左下角)在此之後入口類別和之後的日期。

希望有人能想出這件事XD 在此先感謝!

+0

所以你只需要顯示類別和日期的條目標題? –

+0

是的,這是計劃,但我似乎無法弄清楚如何.. –

回答

0

接聽/最後更新:

從您發佈的代碼,似乎最後一行是有關的一個:

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);} 

您將需要添加一個新的參數和使用參數交換。 嘗試用這種替代這一行:

// 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);} 

您可以找到有關here官方抄本頁面上printf()更多的信息和解釋。

爲了更好地交代看看這個例子:

$city = 'New York'; 
$zipcode = '12345'; 

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

將變爲:

「你的城市是紐約,和你的郵政編碼是」。


更新:(使用get_the_title()之前)

我可以在你的源代碼與標題中的新元素在錯誤的地方加入看到,入門元容器之前。

在源代碼中看到這一點:

<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> 

如果我的代碼改成這樣:

<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> 

標題被添加到正確的地方。 請參閱: post-title on right place

你創建span元素與類post-date自己呢? 您的printf()功能目前正在尋找?

P.S. 也許還可以嘗試使用the_title()而不是beforeafter,看看是否改變了一些東西。

當您使用的printf()也許你需要使用get_the_title()而不是the_title()

+0

嗨LWS莫,感謝您的答覆。我已經實現了你的代碼,這是我自己嘗試過的。但奇怪的是,標題仍然打印在投資組合項目之上。即使當我使用相同的日期或類別的CSS。查看代碼的結果:[鏈接](http://untoldworks.com)我沒有看到一些CSS負責? –

+0

我看了一下該網站的開發者工具。看起來新創建的標題元素添加在錯誤的地方。看到我上面更新的答案。 –

+0

奇怪的是,新的標題元素放置在div之外,因爲如果你看看printf()函數,它應該在裏面。 'printf('

',$ categories_list,$ posting_on,$ edit_post_link,$ my_title);'也嘗試過使用the_title()而沒有其他任何東西,但它只是不顯示。 –