2011-09-30 114 views
0

我在使用WordPress。我很欣賞被展示的代碼,但這是我直接瞭解如何自己做的一件事 - 所以如果你知道我在哪裏可以找到一個教程或可以給我的信息,我會很感激!如何在另一個PHP代碼中插入PHP代碼?

我打電話的帖子,並希望在PHP代碼中包含一個PHP代碼,這是一個主題選項面板。

<?php 
query_posts('cat=-51&posts_per_page=3&paged='.$paged); 
if (have_posts()) : 
?> 

凡51我想把:

<?php echo get_option('to_postc_home'); ?> 

凡3是我想把:

<?php echo get_option('to_posti_home'); ?> 

回答

3

如果我解釋吧,這是你需要什麼,可以使用連接符.到位明文EX的使用這些功能:'this is text''this '.get_option('stuff').' text'

<?php 
    query_posts('cat='.get_option('to_postc_home').'&posts_per_page='.get_option('to_posti_home').'&paged='.$paged); 
    if (have_posts()) : 
?> 
0

了包括從所使用的其他文件的PHP文件include功能

0

無論你想要什麼,都可以使用它

<?php 
query_posts('cat=-51&posts_per_page=3&paged='.$paged); 
if (have_posts()) : 
?> 
hello world 
<?php echo get_option('to_postc_home'); 
endif; 
0
<?php 
    $a = get_option('to_postc_home'); 
    $b = get_option('to_posti_home'); 

    query_posts("cat={$a}&posts_per_page={$b}&paged={$paged}"); 

    if (have_posts()) 
?> 
0

也就是說稱爲字符串連接,並且當您將文字字符串'cat=-51&posts_per_page=3&paged='與變量$paged連接起來時,您已經在代碼的第一行使用該字符串。在PHP中,.運算符會這樣做。

所以,在你的代碼,你可以這樣做:

<?php 
query_posts('cat=-' . get_option('to_postc_home') . '&posts_per_page=' . get_option('to_posti_home') . '&paged='.$paged); 
?> 

這將注入函數的輸出在您指定的地方調用。

0
<?php 
$cat = get_option('to_postc_home'); 
$per_page = get_option('to_posti_home'); 

query_posts("cat=${cat}&posts_per_page=${per_page}&paged=".$paged); 
if (have_posts()) 
?>