Skip to content

Commit a1515be

Browse files
committed
Improvements form Blog Author
1 parent 6a77110 commit a1515be

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

Block/Author/PostList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ protected function _prepareLayout()
4848
if ($author = $this->getAuthor()) {
4949
$this->_addBreadcrumbs($author->getTitle(), 'blog_author');
5050
$this->pageConfig->addBodyClass('blog-author-' . $author->getIdentifier());
51-
$this->pageConfig->getTitle()->set($author->getTitle());
51+
$this->pageConfig->getTitle()->set($author->getMetaTitle());
52+
$this->pageConfig->setKeywords($author->getMetaKeywords());
53+
$this->pageConfig->setDescription($author->getMetaDescription());
5254

5355
if ($this->config->getDisplayCanonicalTag(\Magefan\Blog\Model\Config::CANONICAL_PAGE_TYPE_AUTHOR)) {
5456
$this->pageConfig->addRemotePageAsset(

Controller/Author/View.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function execute()
3737

3838
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_blog_author', $author);
3939

40-
$this->_view->loadLayout();
41-
$this->_view->renderLayout();
40+
$resultPage = $this->_objectManager->get(\Magefan\Blog\Helper\Page::class)
41+
->prepareResultPage($this, $author);
42+
return $resultPage;
4243
}
4344

4445
/**

Model/Author.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ public function getTitle()
6262
return $this->getName();
6363
}
6464

65+
/**
66+
* Retrieve meta title
67+
* @return string
68+
*/
69+
public function getMetaTitle()
70+
{
71+
$title = $this->getData('meta_title');
72+
if (!$title) {
73+
$title = $this->getTitle();
74+
}
75+
76+
return trim($title);
77+
}
78+
79+
/**
80+
* Retrieve meta description
81+
* @return string
82+
*/
83+
public function getMetaDescription()
84+
{
85+
$desc = $this->getData('meta_description');
86+
if (!$desc) {
87+
$desc = $this->getData('content');
88+
}
89+
90+
$desc = strip_tags($desc);
91+
if (mb_strlen($desc) > 300) {
92+
$desc = mb_substr($desc, 0, 300);
93+
}
94+
95+
return trim($desc);
96+
}
97+
6598
/**
6699
* Retrieve author identifier
67100
* @return string | null

etc/adminhtml/system.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@
217217
</field>
218218
<field id="robots" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
219219
<label>Default Robots</label>
220+
<depends>
221+
<field id="enabled">1</field>
222+
</depends>
220223
<source_model>Magento\Config\Model\Config\Source\Design\Robots</source_model>
221224
<comment>This will be included before head closing tag in page HTML.</comment>
222225
</field>

view/frontend/templates/post/view/relatedposts.phtml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
?>
1616

1717
<?php if ($block->displayPosts()) { ?>
18-
<?php $_postCollection = $block->getPostCollection(); ?>
19-
<?php if ($_postCollection->count()) { ?>
18+
<?php $postCollection = $block->getPostCollection(); ?>
19+
<?php if (count($postCollection)) { ?>
2020
<div class="block related">
2121
<div class="block-title title">
2222
<strong id="block-relatedposts-heading" role="heading" aria-level="2">
23-
<?php echo __('Related Posts') ?>
23+
<?= __('Related Posts') ?>
2424
</strong>
2525
</div>
2626
<ol class="block-content">
27-
<?php foreach ($_postCollection as $_post) { ?>
27+
<?php foreach ($postCollection as $post) { ?>
2828
<li class="item">
29-
<a class="post-item-link"
30-
href="<?php echo $_post->getPostUrl() ?>">
31-
<?php echo $block->escapeHtml($_post->getTitle()); ?>
29+
<a class="post-item-link" title="<?= $block->escapeHtml($post->getTitle()) ?>"
30+
href="<?= $post->getPostUrl() ?>">
31+
<?= $block->escapeHtml($post->getTitle()) ?>
3232
</a>
3333
</li>
3434
<?php } ?>
3535
</ol>
3636
</div>
3737
<?php } ?>
38-
<?php } ?>
38+
<?php } ?>
39+

0 commit comments

Comments
 (0)