Skip to content

Commit

Permalink
Cleanup and refactoring (#6)
Browse files Browse the repository at this point in the history
- templates with the same innards has new tpl
- created tpl utils
- created basic templates for pages
- removed redundant template
  • Loading branch information
Veronika Dvořáková authored and VencaV committed Jul 23, 2018
1 parent a4e6f57 commit c192629
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 179 deletions.
24 changes: 5 additions & 19 deletions author.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

<section class="section section-perex">
<div class="section-inner container">
<?php get_template_part( 'template-parts/utils/content', 'breadcrumb' ); ?>

<?php
$author_has_custom_gravatar = validate_gravatar(get_the_author_meta('email'));
if ( $author_has_custom_gravatar ) {
echo '<div class="row"><div class="category-image col-xs-12 col-sm-2">';
echo '<div class="row category-header"><div class="category-image col-xs-12 col-sm-2">';
echo get_avatar( get_the_author_meta( 'ID' ));
echo '</div><div class="col-xs-12 col-sm-10">';
}
Expand All @@ -14,7 +16,7 @@
<h1><?php the_author(); ?></h1>

<?php if ( get_the_author_meta( 'description' ) ) : ?>
<div class="author-description"><?php the_author_meta( 'description' ); ?></div>
<div class="author-description"><?php the_author_meta( 'description' ); ?></div>
<?php endif; ?>

<?php
Expand All @@ -25,22 +27,6 @@
</div>
</section>

<section class="section section-primary">
<div class="section-inner container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;

get_template_part( 'template-parts/post/content', 'pagination' );

else : ?>
Žádné výsledky nenalezeny.
<?php
endif;
?>
</div>
</section>
<?php get_template_part( 'template-parts/post/content', 'section-primary' ); ?>

<?php get_footer(); ?>
34 changes: 14 additions & 20 deletions category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@

<section class="section section-perex">
<div class="section-inner container">
<?php get_template_part( 'template-parts/post/content', 'breadcrumb' ); ?>
<div class="category-header">
<?php
<?php get_template_part( 'template-parts/utils/content', 'breadcrumb' ); ?>

<?php
$current_category = get_queried_object();
$category_image = get_term_meta( $current_category->term_id, 'category_image', true );
if ( $category_image ) {
echo '<div class="row category-header"><div class="category-image col-xs-12 col-sm-2">';
echo '<img src="' . $category_image . '" />';
echo '</div><div class="col-xs-12 col-sm-10">';
}
?>
<h1><?php single_cat_title(); ?></h1>
</div>
<?php echo category_description(); ?>
</div>
</section>
?>

<section class="section section-primary">
<div class="section-inner container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;
<h1><?php single_cat_title(); ?></h1>

get_template_part( 'template-parts/post/content', 'pagination' );
<?php echo category_description(); ?>

else : ?>
Žádné výsledky nenalezeny.
<?php
endif;
if ( $category_image ) {
echo '</div><!-- !.col --></div><!-- !.row -->';
}
?>

</div>
</section>

<?php get_template_part( 'template-parts/post/content', 'section-primary' ); ?>

<?php get_footer(); ?>
43 changes: 42 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function shp_breadcrumb() {
}

} elseif (is_page()) {
echo '<li class="breadcrumb-item">' . get_the_title .'</li>';
echo '<li class="breadcrumb-item">' . get_the_title() .'</li>';
}
}
elseif (is_tag()) { single_tag_title(); }
Expand Down Expand Up @@ -433,4 +433,45 @@ function shp_bootstrap_alert( $atts, $shortcode_content ) {
}
add_shortcode( 'shp_bootstrap_alert', 'shp_bootstrap_alert' );

/*
Shortcode for Shoptet project counts
[projectsCount]
*/
function wp_getStats() {
$cacheFile = 'wp-content/uploads/counters.cached';
$modifyLimit = 3600; // hour in seconds


if (!file_exists($cacheFile) || (time() - filemtime($cacheFile) > $modifyLimit)) {
$tmp = @file_get_contents('https://www.shoptet.cz/projectAction/ShoptetStatisticCounts/Index');
if ($tmp !== FALSE) {
file_put_contents(
$cacheFile,
$tmp
);
}
}

$content = file_get_contents($cacheFile);
if ($content !== FALSE) {
return (array) json_decode($content);
}

return array(
'projectsCount' => 8060,
'transactionsCount' => 81476,
'sales' => 32020068
);
}

function wp_showProjectsCount() {
$projectStats = wp_getStats();
if(!empty($projectStats) && !empty($projectStats['projectsCount'])) {
return $projectStats['projectsCount'];
} else {
return '13700';
}
}
add_shortcode('projectCount', 'wp_showProjectsCount');

?>
31 changes: 22 additions & 9 deletions page.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
<?php get_header(); ?>

<?php
while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/page/content', 'title' ); ?>
<?php get_template_part( 'template-parts/page/content', 'content' ); ?>
<?php
endwhile;
?>

<?php get_footer();
<section class="section section-primary">
<div class="section-inner container">
<?php get_template_part( 'template-parts/utils/content', 'breadcrumb' ); ?>

<?php
/* Start the Loop */
while ( have_posts() ) : the_post();

get_template_part( 'template-parts/page/content', 'content' );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

endwhile; // End of the loop.
?>

</div>
</section>

<?php get_footer(); ?>
24 changes: 4 additions & 20 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@

<section class="section section-perex">
<div class="section-inner container">
<?php get_template_part( 'template-parts/post/content', 'breadcrumb' ); ?>
<?php get_template_part( 'template-parts/utils/content', 'breadcrumb' ); ?>
<?php if ( have_posts() ) : ?>
<h1>Výsledky vyhledávání pro <strong><?php echo get_search_query(); ?></strong></h1>
<h1><?php _e( 'Výsledky vyhledávání pro', 'shp' ); ?> <strong><?php echo get_search_query(); ?></strong></h1>
<?php else : ?>
<h1>Žádné výsledky pro <strong><?php echo get_search_query(); ?></strong></h1>
<h1><?php _e( 'Žádné výsledky pro', 'shp' ); ?> <strong><?php echo get_search_query(); ?></strong></h1>
<?php endif; ?>
</div>
</section>

<section class="section section-primary">
<div class="section-inner container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;

get_template_part( 'template-parts/post/content', 'pagination' );

else : ?>
Žádné výsledky nenalezeny.
<?php
endif;
?>
</div>
</section>
<?php get_template_part( 'template-parts/post/content', 'section-primary' ); ?>

<?php get_footer(); ?>
2 changes: 1 addition & 1 deletion single.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<section class="section section-primary">
<div class="section-inner container">
<?php get_template_part( 'template-parts/post/content', 'breadcrumb' ); ?>
<?php get_template_part( 'template-parts/utils/content', 'breadcrumb' ); ?>

<?php
/* Start the Loop */
Expand Down
18 changes: 1 addition & 17 deletions tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
</div>
</section>

<section class="section section-primary">
<div class="section-inner container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;

get_template_part( 'template-parts/post/content', 'pagination' );

else : ?>
Žádné výsledky nenalezeny.
<?php
endif;
?>
</div>
</section>
<?php get_template_part( 'template-parts/post/content', 'section-primary' ); ?>

<?php get_footer(); ?>
9 changes: 1 addition & 8 deletions page-index.php → template-parts/page/content-claim.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?php /* Template Name: Homepage template */ ?>
<?php get_header(); ?>

<section class="section section-claim">
<div class="section-inner container">
<div class="claim">
Expand All @@ -9,8 +6,4 @@
</div>
</div>
</div>
</section>

<?php get_template_part( 'src/template-parts/page/content', 'index' ); ?>

<?php get_footer(); ?>
</section>
15 changes: 9 additions & 6 deletions template-parts/page/content-content.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<section class="section section-primary">
<div class="section-inner container">
<?php the_content(); ?>
<?php get_template_part( 'template-parts/page/content', 'widget' ); ?>
</div>
</section>
<?php

echo '<h1>' . get_the_title() . '</h1>';

the_content();

get_template_part( 'template-parts/post/content', 'widget' );

?>
34 changes: 0 additions & 34 deletions template-parts/page/content-excerpt.php

This file was deleted.

5 changes: 0 additions & 5 deletions template-parts/page/content-title.php

This file was deleted.

9 changes: 0 additions & 9 deletions template-parts/post/content-breadcrumb.php

This file was deleted.

2 changes: 1 addition & 1 deletion template-parts/post/content-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

get_template_part( 'template-parts/post/content', 'tags' );

get_template_part( 'template-parts/post/content', 'navigation' );
get_template_part( 'template-parts/utils/content', 'navigation' );

?>
9 changes: 0 additions & 9 deletions template-parts/post/content-pagination.php

This file was deleted.

20 changes: 20 additions & 0 deletions template-parts/post/content-section-primary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section class="section section-primary">
<div class="section-inner container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;

get_template_part( 'template-parts/utils/content', 'pagination' );

else : ?>
<h2><?php _e( 'Je nám líto, ale požadovaná stránka nebyla nalezena.', 'shp' ); ?></h2>
<p><?php _e( 'Zkuste prosím použít vyhledávání', 'shp' ); ?></p>

<?php get_template_part( 'template-parts/search/content', 'search' ); ?>
<?php
endif;
?>
</div>
</section>
4 changes: 2 additions & 2 deletions template-parts/search/content-search.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<form action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get" role="search">
<fieldset>
<div class="input-group">
<input type="search" name="s" class="form-control" value="<?php the_search_query(); ?>" placeholder="Zadejte hledaný výraz..." />
<input type="search" name="s" class="form-control" value="<?php the_search_query(); ?>" placeholder="<?php _e( 'Zadejte hledaný výraz...', 'shp' ); ?>" />
<div class="input-group-append">
<button type="submit" class="btn btn-primary">Hledat</button>
<button type="submit" class="btn btn-primary"><?php _e( 'Hledat', 'shp' ); ?></button>
</div>
</div>
</fieldset>
Expand Down
File renamed without changes.
Loading

0 comments on commit c192629

Please sign in to comment.