Page 1 of 1
Display Article and Category data separately
Posted: Fri Mar 01, 2019 4:22 am
by Mark
Greetings,
(Mediumish Theme)
I am trying to make a unique page for categories. Is there a php argument I can use?
For all other content it should work as is.
for Categories it should only display the Category name and description. Thank you to
bayerberg for the snippet.
I don't know if I should add it to the page.php or find a way to get it to grab a whole other template like category.php and build it separate. Either way I would still need the argument - if/then code right?
Sorry I don't know php, (I guess good sometimes) I know css and html pretty well.
Code: Select all
<?php $categoryKey = $page->categoryKey();
$category = getCategory($categoryKey);
echo '<h2>' . $category->name(). '</h2>';
echo '<h4>' . $category->description(). '</h4>'; ?>
If you need further information or clarification please advise.
Thanks so much!
Re: Display Article and Category data separately
Posted: Fri Mar 01, 2019 11:57 am
by bayerberg
you need one page with all categories and all pages in particular category?
Re: Display Article and Category data separately
Posted: Fri Mar 01, 2019 12:36 pm
by Mark
Ideally both.
1) Would act as a sitemap displaying all categories and their related pages. [Link from main navigation bar]
2) Would display the single category and all related pages. [Link from tag at the bottom of the post] The theme already has this ability but it does not display the description of the category.
Thanks again for your help!
Re: Display Article and Category data separately
Posted: Fri Mar 01, 2019 1:52 pm
by bayerberg
index.php
update the loop to display a category template, it should look like this
Code: Select all
if ($WHERE_AM_I == 'page') {
include(THEME_DIR_PHP.'page.php');
} elseif ($WHERE_AM_I=='category') {
include(THEME_DIR_PHP.'category.php');
} else {
include(THEME_DIR_PHP.'home.php');
}
category.php
create the template file in the php folder. you can copy home.php but it would be better to do this
Code: Select all
<div class="container">
<div class="section-title">
<h2><span><?php $category = getCategory($categoryKey); echo $category->name(); ?></span></h2>
</div>
<div class="card-columns listrecent">
<?php if (empty($content)) { $language->p('No pages found'); } ?>
<?php foreach ($content as $page): ?>
<div class="card">
<a href="<?php echo $page->permalink(); ?>">
<div style="background-image:url(<?php echo ($page->coverImage()?$page->coverImage():Theme::src('img/noimage.png')) ?>); background-size: cover; background-position: center; width:100%; height:250px;"></div>
</a>
<div class="card-block p-3">
<h2 class="card-title"><a href="<?php echo $page->permalink(); ?>"><?php echo $page->title(); ?></a></h2>
<h4 class="card-text"><?php echo (empty($page->description())?$language->p('Complete the description of the article'):$page->description()) ?></h4>
<div class="metafooter">
<div class="wrapfooter">
<span class="meta-footer-thumb">
<img class="author-thumb" src="<?php echo ($page->user('profilePicture')?$page->user('profilePicture'):Theme::src('img/noimage.png')) ?>" alt="<?php echo $page->user('nickname') ?>">
</span>
<span class="author-meta">
<span class="post-name"><?php echo $page->user('nickname'); ?></span><br/>
<span class="post-date"><?php echo $page->date(); ?></span><span class="dot"></span><span class="post-read"><?php echo $page->readingTime(); ?></span>
</span>
<span class="post-read-more"><a href="<?php echo $page->permalink(); ?>" title="Read Story"><svg class="svgIcon-use" width="25" height="25" viewbox="0 0 25 25"><path d="M19 6c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2v14.66h.012c.01.103.045.204.12.285a.5.5 0 0 0 .706.03L12.5 16.85l5.662 4.126a.508.508 0 0 0 .708-.03.5.5 0 0 0 .118-.285H19V6zm-6.838 9.97L7 19.636V6c0-.55.45-1 1-1h9c.55 0 1 .45 1 1v13.637l-5.162-3.668a.49.49 0 0 0-.676 0z" fill-rule="evenodd"></path></svg></a></span>
</div>
</div>
</div>
</div>
<?php endforeach ?>
</div>
<?php if (Paginator::numberOfPages()>1): ?>
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<?php if (Paginator::showPrev()): ?>
<li class="page-item"><a class="page-link" href="<?php echo Paginator::previousPageUrl() ?>" tabindex="-1">◀ <?php $language->p('Previous page') ?></a></li>
<?php endif ?>
<?php if (Paginator::showNext()): ?>
<li class="page-item"><a class="page-link" href="<?php echo Paginator::nextPageUrl() ?>"><?php $language->p('Next page') ?> ►</a></li>
<?php endif ?>
</ul>
</nav>
<?php endif ?>
<div class="footer">
<p class="pull-left">
<?php echo $site->footer(); ?>
</p>
<p class="pull-right">
Designed by <a target="_blank" href="https://www.wowthemes.net">Wowthemes</a> |
Powered by <a target="_blank" href="https://www.bludit.com">Bludit.com</a>
</p>
<div class="clearfix">
</div>
</div>
</div>
home.php
find author-meta span, inside that, next to the user name add category, should look something like this
Code: Select all
<span class="post-name"><?php echo $page->user('nickname'); ?></span>
<?php
if ($page->categoryKey()){
$categoryKey = $page->categoryKey();
$category = getCategory($categoryKey);
echo ', <a href="'.$category->permalink().'">'.$category->name().'</a> ';
};
?>
<br/>
topbar.php
add categories to the menu - find static pages loop and after endforeach add this
Code: Select all
$items = getCategories();
foreach ($items as $category) {
if (count($category->pages())>0) {
echo '<li class="nav-item">';
echo '<a class="nav-link" href="'. $category->permalink().'">';
echo $category->name();
echo '</a></li>';
}
}
DONE!
Re: Display Article and Category data separately
Posted: Sat Mar 02, 2019 1:25 am
by Mark
I sort of see what you are doing here but not all the way.
Still missing some pieces but I think it is my fault for not doing enough research.
I was mistaken when I said the Categories have a link already at the bottom of the posts. Actually they are tags. They use this code.
Code: Select all
<!-- Begin Tags -->
<?php if (!empty($page->tags(true))): ?>
<div class="after-post-tags">
<ul class="tags">
<?php foreach ($page->tags(true) as $tagKey=>$tagName): ?>
<li><a href="<?php echo DOMAIN_TAGS.$tagKey ?>"><?php echo $tagName; ?></a></li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
<!-- End Tags -->
I assume I can substitute the tag info for category info? What changes?
Thanks again.
Re: Display Article and Category data separately
Posted: Sat Mar 02, 2019 6:20 pm
by Mark
I did some searching in other themes and was able to solve my own issue.
Use this for the category code to look like a tag at the end of a post.
Code: Select all
<?php if ($page->category()):?>
<div class="after-post-tags">
<ul class="tags">
<li><a href="<?php echo DOMAIN_CATEGORIES.$page->categoryKey() ?>" rel="tag">
<?php echo $page->category() ?></a></li>
</ul>
<?php endif?>