私は、フォームから提示されたURLリンクがあればURLリンクを表示するコードを書こうとしています。基本的なphp 'then then' wordpressのURLリンク
If > [a link exists]
then [display the text 'more info' with the href link wrapped around it]
私はwordpressとphpを混ぜるのを混乱させてしまいました。どんな助けも素晴らしいだろう。
私は、フォームから提示されたURLリンクがあればURLリンクを表示するコードを書こうとしています。基本的なphp 'then then' wordpressのURLリンク
If > [a link exists]
then [display the text 'more info' with the href link wrapped around it]
私はwordpressとphpを混ぜるのを混乱させてしまいました。どんな助けも素晴らしいだろう。
この質問は非常に具体的ではありませんが、私が提供できる擬似コードはこれです:
<?php if (isset($_GET['url'])): ?>
<a href="<?php echo $_GET['url']; ?>">Read more</a>
<?php endif; ?>
は、あなたがポストに表示されたコメントには、このような何かを探していますか?
コメント:「私はhttps://www.google.com/が好きです」が「私はmore infoが好きになります。
そのような場合、おそらくを検索し、URLを交換するfunctions.php
にフィルタを追加すると、トリックを行うかもしれませんが:
// define the get_comment_text callback
function filter_get_comment_text($comment_comment_content, $comment, $args) {
// Regular expression to find URL
$pattern = '/(https?):\/\/(www\.)?[a-z0-9\.:].*?(?=\s)/i';
// Replace url with linked "more info"
$replacement = '<a href="$0">more info</a>';
// Find matches & replace
$newcomment = preg_replace($pattern, $replacement, $comment_comment_content);
// Return the comment
return $newcomment;
};
// add the filter
add_filter('get_comment_text', 'filter_get_comment_text', 10, 3);
あなたはより多くのあなたの質問を明確にしてくださいことはできますか?多分例を追加することさえできますか? – Rabin
提出されたフォームにURLが存在する場合、OPは自動的にクリック可能なリンクを作成するように見えます。 – milesper