我想传入svg箭头图像作为WordPress帖子分页循环的prev_text和next_text。目前,我有localhost urls硬编码。我想设置它,所以这些使用get_template_directory_uri()或类似。
当前代码:
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'next_text' => ('<img class="next-arrow" src="http://localhost:8888/mockingbird/wp-content/themes/mockingbird/images/arrow.svg" alt="next posts"/>'),
'prev_text' => ('<img class="prev-arrow" src="http://localhost:8888/mockingbird/wp-content/themes/mockingbird/images/arrow.svg" alt="previous posts"/>'),
'total' => $query->max_num_pages
) );
?>
我想要的Psuedo代码如下:
'next_text' => ('<img class="next-arrow" src="<?php echo get_template_directory_uri(); ?>/images/arrow.svg" alt="next posts"/>'),
'prev_text' => ('<img class="prev-arrow" src="<?php echo get_template_directory_uri(); ?>/images/arrow.svg" alt="previous posts"/>'),
所以我的问题是,是否可以在数组的字符串中传入php?
如果没有,我如何在没有硬编码的情况下实现这一目标?
答案 0 :(得分:0)
通过将next_text和prev_text设置为空字符串,然后将arrow.svg设置为我的CSS中下一个和上一个链接的背景图像,找出解决方案。
这样,我的图片网址就是我的css中设置的相对路径。
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <locale>
using namespace std;
bool palindrome( string, int, int );
bool isAlpha( string );
string charToString( char );
string normalString( string );
char stringToChar( string );
string vectorToString( vector<string> );
int main()
{
cout << "Enter a word or a sentence: ";
string str;
while( cin >> str )
{
palindrome( normalString(str), 0, normalString(str).size() - 1 ) ? cout << str << " is palindrome!" << " (" << normalString(str) << ") "
<< '\n' : cout << str << " is not palindrome!" << " (" << normalString(str) << ") " << '\n';
cout << "Enter a word or a sentence: ";
}
return 0;
}
string vectorToString( vector<string> vec )
{
stringstream ss;
for( int i = 0; i < vec.size(); ++i )
ss << vec[ i ];
string str;
ss >> str;
return str;
}
string charToString( char c )
{
stringstream ss;
string s;
ss << c;
ss >> s;
return s;
}
char stringToChar( string str )
{
stringstream ss;
ss << str;
char c;
ss >> c;
return c;
}
bool isAlpha( string s )
{
return s == "a" || s == "b" || s == "c" || s == "d" || s == "e" || s == "f" || s == "g" || s == "h" || s == "i" || s == "j" || s == "k" || s == "l"||
s == "m" || s == "n" || s == "o" || s == "p" || s == "q" || s == "r" || s == "s" || s == "t" || s == "u" || s == "v" || s == "w" || s == "x"||
s == "y" || s == "z" ||
s == "A" || s == "B" || s == "C" || s == "D" || s == "E" || s == "F" || s == "G" || s == "H" || s == "I" || s == "J" || s == "K" || s == "L"||
s == "M" || s == "N" || s == "O" || s == "P" || s == "Q" || s == "R" || s == "S" || s == "T" || s == "U" || s == "V" || s == "W" || s == "X"||
s == "Y" || s == "Z" ;
}
string normalString( string str )
{
vector<string> vec;
for( int i = 0; i < str.size(); ++i )
vec.push_back( charToString(str[ i ]) );
for( int i = 0; i < vec.size(); ++i )
{
if( !isAlpha( vec[ i ] ) )
vec[ i ].erase();
if( isupper( stringToChar(vec[ i ]) ) )
vec[ i ] = charToString( tolower( stringToChar( vec[ i ] ) ) );
}
string str2 = vectorToString( vec );
return str2;
}
bool palindrome( string str, int first, int last )
{
if( first == str.size() - 1 ) //if string is a single alphabet.
return true;
if( str[ first ] == str[ last ] )
return palindrome( str.substr( first + 1, last - 1 ), first, last - 2 );
}
CSS:
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'next_text' => (''),
'prev_text' => (''),
'total' => $query->max_num_pages
) );
?>