■ユーザーズフォーラム リニューアルのお知らせ
新規投稿は新ユーザーズフォーラムにお願いします。

ブログの記事のPrev/Nextの部分の≫、≪マークの削除もしくは変更

 

<前のページ |  1  |  2  

Nori > Re: ブログの記事のPrev/Nextの部分の≫、≪マークの削除もしくは変更 @ 2018/10/29 15:56
<?php
/**
 * ブログ詳細ページ
 */
$this->BcBaser->setDescription($this->Blog->getTitle() . '|' . $this->Blog->getPostContent($post, false, false, 50));

# single.php

function getPrevPost($post) {
			$_htmlAttributes = ['class' => 'prev-link', 'arrow' => ''];
		$htmlAttributes = am($_htmlAttributes, $htmlAttributes);
		$arrow = $htmlAttributes['arrow'];
		unset($htmlAttributes['arrow']);
		if ($prevPost) {
			if (!$title) {
				$title = $arrow . $prevPost['BlogPost']['name'];
			}
			echo $this->getPostLink($prevPost, $title, $htmlAttributes);
		}

}

function getNextPost($post) {
			$_htmlAttributes = ['class' => 'next-link', 'arrow' => ''];
		$htmlAttributes = am($_htmlAttributes, $htmlAttributes);
		$arrow = $htmlAttributes['arrow'];
		unset($htmlAttributes['arrow']);
		if ($nextPost) {
			if (!$title) {
				$title = $nextPost['BlogPost']['name'] . $arrow;
			}
			echo $this->getPostLink($nextPost, $title, $htmlAttributes);
		}

}
?>


上記のように既存の所にBlogHelperの該当箇所と思うところを修正し追記しましたが、
変化せず、相変わらず≪もしくは≫マークが表示されます…

なにか間違いありますでしょうか?

■ BaserCMSのバージョン:4.1.3
■ レンタルサーバー名:ロリポップ
■ スマートURLの利用:OFF
■ 設置フォルダ:サブフォルダ
■ 利用しているデータベース:MySQL
■ PHPスキル:D

seto > Re: ブログの記事のPrev/Nextの部分の≫、≪マークの削除もしくは変更 @ 2018/10/30 10:25
Noriさんの書かれたgetPrevPost・getNextPostと、ブログプラグインのgetPrevPost・getNextPostとで、コードが違うようです。

こちらからそのままコピーしてください。
https://github.com/baserproject/basercms/blob/dev-4/lib/Baser/Plugin/Blog/View/Helper/BlogHelper.php#L1151

あとは、こうして使うことで前後の記事のデータが取得できます。
$prevPost = getPrevPost($post);
p($prevPost);

$nextPost = getNextPost($post);
p($nextPost);
Nori > Re: ブログの記事のPrev/Nextの部分の≫、≪マークの削除もしくは変更 @ 2018/10/30 15:36
<?php
/**
 * ブログ詳細ページ
 */
$this->BcBaser->setDescription($this->Blog->getTitle() . '|' . $this->Blog->getPostContent($post, false, false, 50));

# single.php

function getPrevPost($post) {
		$BlogPost = ClassRegistry::init('Blog.BlogPost');
		// 投稿日が年月日時分秒が同一のデータの対応の為、投稿日が同じでIDが大きいデータを検索
		$conditions = [];
		$conditions['BlogPost.id <'] = $post['BlogPost']['id'];
		$conditions['BlogPost.posts_date'] = $post['BlogPost']['posts_date'];
		$conditions['BlogPost.blog_content_id'] = $post['BlogPost']['blog_content_id'];
		$conditions = am($conditions, $BlogPost->getConditionAllowPublish());
		$order = 'BlogPost.posts_date DESC, BlogPost.id DESC';
		// 毎秒抽出条件が違うのでキャッシュしない
		$prevPost = $BlogPost->find('first', [
			'conditions' => $conditions,
			'order' => $order,
			'recursive' => 0,
			'cache' => false
		]);
		if (empty($prevPost)) {
			// 投稿日が古いデータを取得
			$conditions = [];
			$conditions['BlogPost.posts_date <'] = $post['BlogPost']['posts_date'];
			$conditions['BlogPost.blog_content_id'] = $post['BlogPost']['blog_content_id'];
			$conditions = am($conditions, $BlogPost->getConditionAllowPublish());
			// 毎秒抽出条件が違うのでキャッシュしない
			$prevPost = $BlogPost->find('first', [
				'conditions' => $conditions,
				'order' => $order,
				'recursive' => 0,
				'cache' => false
			]);
		}
		return $prevPost;
	}

function getNextPost($post) {
		$BlogPost = ClassRegistry::init('Blog.BlogPost');
		// 投稿日が年月日時分秒が同一のデータの対応の為、投稿日が同じでIDが小さいデータを検索
		$conditions = [];
		$conditions['BlogPost.id >'] = $post['BlogPost']['id'];
		$conditions['BlogPost.posts_date'] = $post['BlogPost']['posts_date'];
		$conditions['BlogPost.blog_content_id'] = $post['BlogPost']['blog_content_id'];
		$conditions = am($conditions, $BlogPost->getConditionAllowPublish());
		$order = 'BlogPost.posts_date, BlogPost.id';
		// 毎秒抽出条件が違うのでキャッシュしない
		$nextPost = $BlogPost->find('first', [
			'conditions' => $conditions,
			'order' => $order,
			'recursive' => 0,
			'cache' => false
		]);
		if (empty($nextPost)) {
			// 投稿日が新しいデータを取得
			$conditions = [];
			$conditions['BlogPost.posts_date >'] = $post['BlogPost']['posts_date'];
			$conditions['BlogPost.blog_content_id'] = $post['BlogPost']['blog_content_id'];
			$conditions = am($conditions, $BlogPost->getConditionAllowPublish());
			// 毎秒抽出条件が違うのでキャッシュしない
			$nextPost = $BlogPost->find('first', [
				'conditions' => $conditions,
				'order' => $order,
				'recursive' => 0,
				'cache' => false
			]);
		}
		return $nextPost;
	}

?>


お疲れ様です。
アドバイスに従い、このように書き直しました。
間違いないでしょうか?

引用:
あとは、こうして使うことで前後の記事のデータが取得できます。
$prevPost = getPrevPost($post);
p($prevPost);

$nextPost = getNextPost($post);
p($nextPost);


この部分がまだ少しわかりません。
申し訳ありませんが今一度アドバイスお願いいたします。

■ BaserCMSのバージョン:4.1.3
■ レンタルサーバー名:ロリポップ
■ スマートURLの利用:OFF
■ 設置フォルダ:サブフォルダ
■ 利用しているデータベース:MySQL
■ PHPスキル:D

seto > Re: ブログの記事のPrev/Nextの部分の≫、≪マークの削除もしくは変更 @ 2018/10/31 12:39
> アドバイスに従い、このように書き直しました。
はい、大丈夫そうです。

> この部分がまだ少しわかりません。
p関数を使うことで、正しく前後の記事を取得できているか確認できると、お伝えしたかったのです。

前後の記事の情報さえ取得できれば、後はprevLink・nextLinkに前後の記事のタイトルを渡すと、目的が達成できるかと思います。

<?php
$prevPost = getPrevPost($post);
$prevPostTitle = $this->Blog->getPostTitle($prevPost, false);
$this->Blog->prevLink($post, $prevPostTitle);
?>

 

<前のページ |  1  |  2  

ログイン
ユーザー名:
パスワード:


  新規登録 / パスワード紛失

検索

facebook
フォーラムで悩みが解決した場合など、よかったら「いいね!」をポチっとクリックしてください!質問の回答者や開発者の励みになります

フォーラムガイド


関連リンク

オンライン状況
26 人のユーザが現在オンラインです。 (26 人のユーザが フォーラム を参照しています。)

登録ユーザ: 0
ゲスト: 26