2014-01-08 55 views
-1

我正在創建一個wordpress網站。 我的客戶要求我在整個php中進行編碼。 但有時,某處無法使用php。 我結合PHP爲HTML如何在HTML網站中將HTML調用到PHP中?

如:

<a class="single_post_title" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> 
<h1 class="single_post_heading heading_blog"><?php the_title(); ?></h1> 
</a> 

如果我使用

<?php 
    echo '<a class="single_post_title" href="'.the_permalink().'" title="'.the_title().'"> 
     <h1 class="single_post_heading heading_blog">'.the_title().'</h1> 
     </a>'; 
?> 

那麼這個詞按網站顯示<a class="single_post_title" href="" title="">而我用火的錯誤檢驗。 href和title屬性是空的。 可能是該功能the_permalink()內建的wordpress的原因,已經迴應鏈接。所以當我使用href="'.the_permalink().'"時,鏈接會在href屬性中重複兩次。

我該如何使用PHP將這些HTML代碼調用到PHP中?

+0

問題更多的細節編輯......可你們經歷好嗎? –

回答

3

嘗試:?

<?php echo '<a class="single_post_title" href="'.get_permalink().'" title="'.get_the_title().'"> 
      <h1 class="single_post_heading heading_blog">'.get_the_title().'</h1> 
      </a>'; 

>

+0

謝謝你。但是輸出是**重要的是要跟上時代的發展。 2013年的網站趨勢?跟上2013年的網站趨勢是否重要? - 更多信息,請訪問:http://www.mysite.com/blog/is-it-important-to-keep-up-with-the-website-trends-in-2013/**表示錨標記HREF不起作用。它只是顯示帖子 –

+2

Erm的鏈接,如果你想返回標題而不是直接打印它,請使用'get_the_title()'而不是'the_title()'。 http://codex.wordpress.org/Function_Reference/get_the_title 'the_permalink()'也一樣。改用'get_permalink()'。 http://codex.wordpress.org/Function_Reference/get_permalink – techouse

+0

其工作就像一個魅力。非常感謝你的伴侶。 –

1

您可以添加HTML到PHP爲:

<?php 
echo '<a class="single_post_title" href="'.the_permalink().'" title="'.the_title().'">'; 
?> 
+0

其工作就像一個魅力。非常感謝你的伴侶。 –

+0

對不起,我在這裏評論錯誤..因爲wordpress需要使用'get_the_permalink()'來達到我的目的。 –

1

這應該工作。

<?php 
    echo '<a class="single_post_title" href="'.get_permalink().'" title="'.get_the_title().'"> 
     <h1 class="single_post_heading heading_blog">'.get_the_title().'</h1> 
     </a>'; 
+0

它像一個魅力工作。非常感謝你的伴侶 –

1
<?php echo '<a class="single_post_title" href="'.get_permalink().'" title="'.get_the_title().'"> 
      <h1 class="single_post_heading heading_blog">'.get_the_title().'</h1> 
      </a>'; 
?> 

enter image description here