Mediumish theme adaptation : list pages from category

Post Reply
myrdin
Jr. Bludit
Posts: 3
Joined: Thu Sep 05, 2019 5:37 pm

Thu Sep 05, 2019 5:49 pm

Hello !

I am very new to bludit and php, I am working on a version of the mediumish theme (https://github.com/bludit-themes/mediumish) and in home.php I would like to display only pages from one category.

Currently it displays the content of the site.

I think I should do something in this part of the file :

Code: Select all

<?php
			// Get the first and second page from the content
			$featured = array_slice($content, 0, 2);
			$content = array_slice($content, 2);
			foreach ($featured as $page):
		?>
What I want is to get the third first pages from category named "structure"

Here is the full code : https://github.com/bludit-themes/medium ... p/home.php

Thank you for your help !
User avatar
Edi
Site Admin
Posts: 1652
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Fri Sep 06, 2019 10:55 am

In this case you have to add an if condition for the selected category.
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
myrdin
Jr. Bludit
Posts: 3
Joined: Thu Sep 05, 2019 5:37 pm

Fri Sep 06, 2019 2:36 pm

Hello and thank you for your answer.

I have tried with

Code: Select all

<?php if ($category->key() == 'structure'): ?>
.

Like this

Code: Select all

<?php if ($WHERE_AM_I == 'home'): ?>

	<!-- Begin Featured
	================================================== -->
	<section class="featured-posts">
	<div class="section-title">
		<h2><span>La structure</span></h2>
	</div>
	<div class="card-columns listfeaturedtag">
		
		<?php if ($category->key() == 'structure'): ?>

		<?php 
			// Get the first and second page from the content
			$featured = array_slice($content, 0, 2);
			$content = array_slice($content, 2); ?>
		
		<?php endif; ?>

		<?php
			foreach ($featured as $page):
		?>
		<!-- begin post -->
		<div class="card">
			<div class="row">
				<div class="col-md-5 wrapthumbnail">
					<a href="<?php echo $page->permalink(); ?>">
						<div class="thumbnail" style="background-image:url(<?php echo ($page->coverImage()?$page->coverImage():Theme::src('img/noimage.png')) ?>);"></div>
					</a>
				</div>
				<div class="col-md-7">
					<div class="card-block">
						<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())?'Complete the description of the article for a correct work of the theme':$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="Author">
								</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>
			</div>
		</div>
		<!-- end post -->
		<?php endforeach; ?>
			
	</div>
	</section>
	<!-- End Featured
	================================================== -->
	<?php endif; ?>
But it does not display the 'structure' articles.
myrdin
Jr. Bludit
Posts: 3
Joined: Thu Sep 05, 2019 5:37 pm

Fri Sep 06, 2019 10:23 pm

If some of you look for the answer I was able to do what I expected with this lines of code :

Code: Select all

        <?php 
            $categoryKey = 'structure';
            $category = getCategory($categoryKey);

            $featured = array_slice($category->pages(), 0, 3);
            $content = array_slice($content, 1); ?>

        <?php
            foreach ($featured as $pageKey):
        ?>

        <?php $page = new Page($pageKey); ?>
User avatar
quenquen
Jr. Bludit
Posts: 9
Joined: Tue Apr 09, 2019 7:36 pm

Wed Sep 11, 2019 1:08 am

Thanks! That last line of code was what I was missing. You saved the day :D

I changed value 1 to 0 to proper display all blog posts, since some new posts was missing from my site.

Code: Select all

$content = array_slice($content, 0); ?>
kostaslgr
Ssr. Bludit
Posts: 11
Joined: Fri Jan 11, 2019 8:58 pm

Thu Oct 24, 2019 11:31 am

I do not know if this helps, but if i want to show only the ports from a category i use the link to the category. For example if i have posts in the category music, the link would be like the following
www.domainname.com/category/music
Post Reply