Any Possible problems with the following? (Code Review)
-
Hey guys…at the moment I am building a theme that I am going to try to provide for free to the community. I have been working with wordpress for the past year and a half now, but this is my first theme that will be distributed to many people, where I have to provide a lot of customization ability, so I am learning a lot as I go.
The blankslate theme that I downloaded did not offer as much as I would have preferred in terms of easy customization. Took a lot of hacking to get smaller things to do exactly what I wanted, and basically figured I would be better off doing it from scratch.
Problem is that I am not quite sure if my substitution would cause any problems? Or if it is even considered good practice?
I set up the archive loop as follows, and was wondering if there is anything that I am missing (such as an already built-in wordpress function)
But basically takes the URL structure for the Archive page that you land on, dissects it, divides it up into year/month/day and then applies a date_query based on it.Is the following “okay” to use in terms of efficiency and would it be considered an acceptable template?
THE FUNCTION THAT “SLICES” THE URL
global $req_year, $req_month, $req_day; $current_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $site_url = site_url(); $site_url_length = strlen($site_url); $current_link = substr($current_link, $site_url_length); $current_link = substr($current_link, 1); /*---------------------- --Remove the End Slash-- ----------------------*/ $current_link = substr($current_link, 0, -1); $current_link_length = strlen($current_link); /*------------------------------------------------------------------------- --Cut up the Current URL that wordpress sets up into Year -> Month -> day-- --When URL Structure = YEAR/MONTH/DAY-------------------------------------- -------------------------------------------------------------------------*/ $req_year = substr($current_link, 0, 4); $req_month = substr($current_link, 5, 2); $req_day = substr($current_link, 8, 2);
THE TEMPLATE PART
<div class="mpostfeed <?php echo $req_year.'-'.$req_month.'-'.$req_day;?>-archives archive-template" > <header class="header"> <h1 class="mp-main-title"><?php if ( is_day() ) { printf( __( 'Daily Archives: %s', 'Evyr2014' ), get_the_time(get_option('date_format') ) ); } elseif ( is_month() ) { printf( __( 'Monthly Archives: %s', 'Evyr2014' ), get_the_time('F Y') ); } elseif ( is_year() ) { printf( __( 'Yearly Archives: %s', 'Evyr2014' ), get_the_time('Y') ); } else { _e( 'Archives', 'Evyr2014' ); } ?></h1> </header> <ul> <?php /*-------------------------------------------------------------------- --Set up the arguments for the query, including the paginated aspect-- --------------------------------------------------------------------*/ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; evyr2014_date_from_url(); global $req_day, $req_month, $req_year, $the_query; if($req_day & $req_month & $req_year){ $args = array( 'post_type' => 'post', 'cat' => '-14', 'date_query' => array( array( 'day' => $req_day, 'year' => $req_year, 'month'=> $req_month, ) ), 'posts_per_page' => 10, 'paged' => $paged ); }elseif(empty($req_day)){ $args = array( 'post_type' => 'post', 'cat' => '-14', 'date_query' => array( array( 'year' => $req_year, 'month'=> $req_month, ) ), 'posts_per_page' => 10, 'paged' => $paged ); }else{ $args = array( 'post_type' => 'post', 'cat' => '-14', 'date_query' => array( array( 'month'=> $req_month, ) ), 'posts_per_page' => 10, 'paged' => $paged ); } /*------------------------------------------------- --Retrieve the query based on the above arguments-- -------------------------------------------------*/ $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); /*--------------------- --Begin the post item-- ---------------------*/ ?> <li class="post-item"> <a href="<?php echo the_permalink();?>"> <span class="featured-bg"> <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(); }else{ ?> <span class="fp-holder"></span> <?php } ?> </span> </a> <a href="<?php echo get_permalink();?>" class="mp-title"><?php the_title();?></a> <span class="mp-excerpt"><?php the_excerpt();?></span> <span class="mp-panel"> <span class="mp-date"> <?php /*-------------------------------------------------- --Sets up the Date in [Month] [Day], [Year] Format-- --------------------------------------------------*/ the_time('F d, Y'); ?> </span> <span class="mp-postcount"> <?php /*--Retrieve the post view count for the designated post--*/ echo getPostViews(get_the_ID()); ?> </span> <a href="<?php echo get_permalink();?>" class="mp-readmore">Read More</a> <span class="divider"></span> </span> </li><!--/.post-item--> <?php ?> <?php endwhile; ?> </ul> <?php get_template_part('assets/parts/feed', 'pagination'); /*--------------------------------- --Reset the arguments and query,--- --So that multiple queries may be-- --set up in a template------------- ---------------------------------*/ wp_reset_postdata(); ?> <?php else: //Do Nothing endif; ?> </div>
I apologize for any unnecessary word wrapping in the code caused by the browser and forum formatting…left the indents so that you guys could just select all and then paste into your text editor to be able to read it better.
Thank you in advance for any support that you are able to toss my way.
- The topic ‘Any Possible problems with the following? (Code Review)’ is closed to new replies.