added support for custom fields and front page show

This commit is contained in:
jorge-vitrubio 2022-12-28 21:56:26 +01:00
parent febdb7a8fe
commit 3929c97ac5
7 changed files with 293 additions and 24 deletions

View File

@ -0,0 +1,53 @@
<?php
/**
* The template for page declared as front-page
*
*
* @link https://developer.wordpress.org/themes/template-files-section/page-template-files/
*
* @package Oficina_de_Suport_theme
*/
get_header();
?>
<main id="primary" class="site-main">
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) :
?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
/* Start the Loop */
while ( have_posts() ) :
the_post();
/*
* Include the Post-Type-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Type name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_type() );
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- #main -->
<?php
get_sidebar();
get_footer();

View File

@ -18,23 +18,21 @@ get_header();
<main id="primary" class="site-main">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
get_template_part( 'template-parts/content', 'page' );
endwhile; // End of the loop.
endwhile; // End of the loop.
endif; // End if have_post.
?>
</main><!-- #main -->
<?php
if ( is_front_page() ) :
get_template_part( 'template-parts/frontpage', 'widgets' );
get_template_part( 'template-parts/section', 'featured' );
endif;
?>
<?php
endif; // End if have_post.
?>
<?php
get_sidebar();

View File

@ -20,8 +20,8 @@ get_header();
the_post_navigation(
array(
'prev_text' => '<span class="nav-subtitle">' . esc_html__( 'Previous:', 'ofisuport' ) . '</span> <span class="nav-title">%title</span>',
'next_text' => '<span class="nav-subtitle">' . esc_html__( 'Next:', 'ofisuport' ) . '</span> <span class="nav-title">%title</span>',
'prev_text' => '<span class="nav-subtitle">' . esc_html__( 'Anterior:', 'ofisuport' ) . '</span> <span class="nav-title">%title</span>',
'next_text' => '<span class="nav-subtitle">' . esc_html__( 'Següent:', 'ofisuport' ) . '</span> <span class="nav-title">%title</span>',
)
);

View File

@ -1,14 +0,0 @@
<?php
/**
* Template part for displaying widgets if we are in front_page
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Oficina_de_Suport_theme
*/
?>
<aside id="destacats" class="">
<?php dynamic_sidebar( 'front-page-widgets' ); ?>
</aside>

View File

@ -0,0 +1,70 @@
<?php
/**
* Template part for displaying featured "ajuts" and widgets
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Oficina_de_Suport_theme
*/
?>
<aside>
<?php
// Detect plugin. For use on Front End only.
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
if ( is_plugin_active( 'oficinasuport-wp-plugin/ofisuport-wp-plugin.php' ) ) {
//plugin is activated do
?>
<header>
<h1> <?php echo esc_html__('Destacats', 'ofisuport'); ?></h1>
</header>
<main id="destacats" class="ofisuport-destacats ofisuport-featured">
<?php //get_template_part( 'template-parts/loop', 'posttype-category-number'); ?>
<?php
// https://developer.wordpress.org/reference/functions/get_posts/
// https://www.advancedcustomfields.com/resources/true-false/
$the_query = new WP_Query(
array(
'post_type' => 'any',
'post_per_page' => '4',
'meta_query' => array(
array(
'key' => 'os_home_show',
'value'=> '1',
)
)
) );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article class="">
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
<section class="excerpt post-excerpt">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_excerpt() ?>
</a>
</section>
</article>
<?php endwhile;//end of the loop ?>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p class="no-content"></p>
<?php endif; //end query ?>
</main>
<?php } //closing if is_plugin_active ?>
<?php // including widget area for front page only ?>
<?php dynamic_sidebar( 'front-page-widgets' ); ?>
</aside>

View File

@ -0,0 +1,89 @@
<?php
/**
* The section containing preview of posts from category
* depending on the call from section-featured.php or whatever
* other template calling this file
*
* @package arcHIVE-theme
* @since arcHIVE-theme 1.0.0
*/
?>
<?php
//https://developer.wordpress.org/reference/functions/get_template_part/#comment-4130
// var_dump( $args ); //will display everythin imported from
// get_template_part( 'template-parts/section', 'category', array('category_name' => 'news', 'post_per_page' => '3' ) );
$thiscategory = $args['category_name'];
$howmanyposts = $args['post_per_page'];
?>
<section class="category-posts <?php echo $thiscategory;?> ">
<header>
<h2>
<?php
if ( is_category() ):
single_cat_title();
else:
echo $thiscategory;
endif;
?>
</h2>
</header>
<main class="">
<?php $the_query = new WP_Query( array( 'category_name' => $thiscategory, 'posts_per_page' => $howmanyposts ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article class="">
<?php if ( has_post_thumbnail() ) :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo get_the_post_thumbnail_url();?>);">
</figure>
</a>
<?php else :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo catch_post_first_image();?>);">
</figure>
</a>
<?php endif;?>
<h5 class="date">
<?php
if ( is_category( 'news' ) ):
the_date('d.m.Y');
else:
the_date('Y');
endif;
?>
</h5>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
<section class="excerpt post-excerpt">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_excerpt() ?>
</a>
</section>
</article>
<?php endwhile;//end of the loop ?>
</main>
<aside>
<?php //get_template_part( 'template-parts/navigation', 'prevnext' ); ?>
<nav>
<?php
// button load more simple
echo '<a class="button hollow" href="' . esc_url( get_site_url( null, $thiscategory ) ) . '">';
echo 'load more ' ;
echo $thiscategory;
echo '</a>';
?>
</nav>
</aside>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
</main>
<?php endif; ?>
</section>

View File

@ -0,0 +1,73 @@
<?php
/**
* The section containing preview of resources
*
* @package arcHIVE-theme
* @since arcHIVE-theme 1.0.0
*/
?>
<?php
//https://developer.wordpress.org/reference/functions/get_template_part/#comment-4130
// var_dump( $args ); //will display everythin imported from
// get_template_part( 'template-parts/section', 'category', array('category_name' => 'news', 'post_per_page' => '3' ) );
$thiscustomposttype = get_post_type( get_the_ID() );
$howmanyposts = $args['post_per_page'];
?>
<section class="archive-posts resources">
<header>
<h2>
<?php
// if ( is_post_type_archive() ):
post_type_archive_title();
// else:
// echo $thiscustomposttype;
// endif;
?>
</h2>
</header>
<main class="">
<?php $the_query = new WP_Query( array( 'post_type' => $thiscustomposttype, 'posts_per_page' => $howmanyposts ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article class="">
<?php if ( has_post_thumbnail() ) :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo get_the_post_thumbnail_url();?>);">
</figure>
</a>
<?php else :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo catch_post_first_image();?>);">
</figure>
</a>
<?php endif;?>
<h5 class="date">
<?php the_date('Y');?>
</h5>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
<section class="excerpt post-excerpt">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_excerpt() ?>
</a>
</section>
</article>
<?php endwhile;//end of the loop ?>
<?php //pagination here if needed?>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</main>
<aside>
<nav>
<!--a href="" class="button hollow">see more news</a-->
</nav>
</aside>
</section>