Advanced Theming

HTMLy almost can list any posts based tag, category, author, or type. You just need to read the functions.php to know any get helper.

With this than we can creating our custom widget.

Get Specific Posts by Tag

We can display list of posts by tag by using built in function:

// $tag = the tag slug
// $page = the page
// $perpage = how many posts
// $random = true or false

get_tag($tag, $page, $perpage, $random)

Let say we already have Featured tag and we want displayed it as posts list.

// get the posts with featured tag
// as 1 page, 4 posts, random false

<?php $featured = get_tag('featured', 1, 4, false);?>

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

// the div etc. goes here.

<div class="content">
    <div class="title"><?php echo $f->title; ?></div>
    //etc....
</div>

<?php endforeach;?>

Get Specific Posts by Category

We can display list of posts by category:

// $category = the category slug
// $page = the page
// $perpage = how many posts

get_category($category, $page, $perpage)

Let say we want to display HTMLy category.

// get the posts categorized as htmly
// as 1 page, 4 posts

<?php $htmly= get_category('htmly', 1, 4);?>

<?php foreach($htmly as $h):?>

// the div etc. goes here.

<div class="content">
    <div class="title"><?php echo $h->title; ?></div>
    //etc....
</div>

<?php endforeach;?>

Other Get Helper

By Specific Keyword (Search)

get_keyword($keyword, $page, $perpage)

By Specific Type (image, video etc.)

get_type($type, $page, $perpage)

By Author

// $name = username

get_profile_posts($name, $page, $perpage)

Get Image From Post

If the content type is image by printing image; ?> will outputting the featured image. We can get an image from regular post or even video thumbnail by calling this function:

get_image($text)

If in post than it become:

get_image($p->body)

Get Specific Static page

get_static_post($static)

Example get "about" page. Always use the slug.

$static = get_static_post('about');

Later we can display it:

<div>
<?php echo $static[0]->title;?>
</div>

Availabe tag:

$static[0]->url;
$static[0]->title;
$static[0]->body;
$static[0]->readTime;

Get specific static sub page

<?php $mySub = get_static_sub_post('parent-page-slug', 'sub-page-slug'); ?>
<?php echo $mySub[0]->body;?>

Displaying sub pages in parent page.

Perhaps you want to displaying the subpage link or even the content in parent page.

<?php
$static = substr($p->url, strrpos($p->url, "/") + 1);
$subPages = get_static_sub_post($static, null);
usort($subPages, function($a, $b) { return $b->file == $a->file ? 0 : (($b->file < $a->file) ? 1 : -1); });
if (isset($is_page) && count($subPages) >= 1):?>

<div class="container">
  <div class="row">
    <?php foreach ($subPages as $sp):?>
        <div class="col-lg-6" style="margin-bottom:2em;">
            <div class="card">
            <h3 class="card-header"><a href="<?php echo $sp->url;?>" style="color:#1a1a1a;"><?php echo $sp->title;?></a></h3>
                <a href="<?php echo $sp->url;?>"><img height="200px" style="object-fit: cover;" class="card-img-top" src="<?php echo get_image($sp->body);?>" alt="<?php echo $sp->title;?>"></a>
                <div class="card-body">
                    <a href="<?php echo $sp->url;?>" class="btn btn-outline-info">Info</a> <a href="<?php echo $sp->url;?>#download" class="btn btn-outline-primary">Download</a> <?php if (login()) { echo '<span><a class="btn btn-info" href="'. $sp->url .'/edit?destination=post">Edit</a></span>'; } ?>
                </div>
            </div>
        </div>
    <?php endforeach;?>
  </div>
</div>

<?php endif;?>

Demo: HTMLy theme page.

Note: the available variable is like on regular static or sub page.