WordPressユーザーのbaserCMS覚え書き


ブログの個別記事へのリンクを出力する

WordPress

the_permalink()

テンプレートタグ/the permalink - WordPress Codex 日本語版

baserCMS(3系)

$this->Blog->postLink($post, $title, [$options])

[postLink] 記事へのリンクを出力する|baserCMS 3系関数リファレンス

メモ

ブログの個別記事へのリンクを出力する関数(テンプレートタグ)で、第2引数 $title でリンク文字列を設定することが可能です。

ただ、個別記事の一覧(indexページやarchiveページなど)の実装でよくある〈記事タイトルへのリンク埋め込み〉は postLink() でなく postTitle() を使う方がシンプルでよいでしょう。

WordPressにて、記事タイトルにリンクを埋める実装例

<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_title( '<h1><a href="' . esc_url( get_permalink() ) . '">', '</a></h1>' ); ?>

baserCMSにて、記事タイトルにリンクを埋める実装例

<h1><?php $this->BcBaser->postTitle($post) ?></h1>

baserCMSの postTitle() はリンクの有無を第2引数にて設定可能です。省略時は true がセットされる(=リンクが埋め込まれる)ので、上記のようなコードでOKというわけです。