Plugin Directory

Changeset 2509295


Ignore:
Timestamp:
04/05/2021 09:17:25 AM (5 years ago)
Author:
ambercouch
Message:

Updated Timber template support

Location:
ac-custom-loop-shortcode/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ac-custom-loop-shortcode/trunk/ac-wp-custom-loop-sc.php

    r2217622 r2509295  
    44  Plugin URI: https://github.com/ambercouch/ac-wp-custom-loop-shortcode
    55  Description: Shortcode  ( [ac_custom_loop] ) that allows you to easily list post, pages or custom posts with the WordPress content editor or in any widget that supports short code. A typical use would be to show your latest post on your homepage.
    6   Version: 1.4.3
     6  Version: 1.5
    77  Author: AmberCouch
    88  Author URI: http://ambercouch.co.uk
     
    2626  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2727 */
     28
     29use Timber\PostQuery;
    2830
    2931defined('ABSPATH') or die('You do not have the required permissions');
     
    5456        ), $atts));
    5557
    56 
     58        $template_type = $type;
    5759
    5860        //default orderby
     
    7072            $type = 'any';
    7173            $orderby = 'post__in';
     74
    7275        }
    7376
     
    7780        $output = '';
    7881        $post_types = get_post_types($args, 'names');
     82
    7983        $theme_directory = $template_path;
    80         //$theme_extention = (substr($template, -4) === '.php' || substr($template, -5) === '.twig' ) ? '' : '.php';
    81         $template = (substr($template, -4) === '.php') ? substr_replace($template ,"",-4) :  $template;
    82         $theme_template = $theme_directory . $template . '.php';
    83         $theme_template_type = $theme_directory . $template . '-' . $type . '.php';
     84
     85
     86        if ($timber != false){
     87            $twig_template_folder = $theme_directory . 'templates/';
     88            $template = (substr($template, -5) === '.twig') ? substr_replace($template ,"",-5) :  $template;
     89            $theme_template = $template . '.twig';
     90            $theme_template_type = $template . '-' . $template_type . '.twig';
     91        }else{
     92
     93            //$theme_extention = (substr($template, -4) === '.php' || substr($template, -5) === '.twig' ) ? '' : '.php';
     94            $template = (substr($template, -4) === '.php') ? substr_replace($template ,"",-4) :  $template;
     95            $theme_template = $theme_directory . $template . '.php';
     96            $theme_template_type = $theme_directory . $template . '-' . $template_type . '.php';
     97        }
    8498
    8599        $wrapperOpen = ($wrapper == 'true') ? '<div class="'.$class.'" >' : '';
     
    98112        }
    99113
    100 
    101         if (file_exists($theme_template_type))
    102         {
    103             $template = $theme_template_type;
    104 
    105         }elseif (file_exists( $theme_template ))
    106         {
    107             $template = $theme_template;
    108 
    109         }else{
    110             $template = "loop-template.php";
    111         }
     114if($timber != false){
     115
     116    if (file_exists($twig_template_folder.$theme_template_type))
     117    {
     118        $template = $theme_template_type;
     119
     120    }elseif (file_exists($twig_template_folder.$theme_template ))
     121    {
     122        $template = $theme_template;
     123    }else{
     124        $template = "loop-template.twig";
     125    }
     126}else{
     127
     128    if (file_exists($theme_template_type))
     129    {
     130        $template = $theme_template_type;
     131
     132    }elseif (file_exists( $theme_template ))
     133    {
     134        $template = $theme_template;
     135    }else{
     136        $template = "loop-template.php";
     137    }
     138}
    112139
    113140        if (!in_array($type, $post_types) && $type != 'any')
     
    163190
    164191            }else{
    165                 $context = Timber::get_context();
    166                 $context['posts'] = Timber::get_posts();
    167                 $templates = array('loop-template.twig');
    168                 ob_start();
    169                 Timber::render( $templates, $context );
    170                 $output .= ob_get_contents();
    171                 ob_end_clean();
     192                if(class_exists('Timber')){
     193
     194                    $context = Timber::get_context();
     195                    $context['posts'] = new Timber\PostQuery();
     196                    $templates = array( $template);
     197                    ob_start();
     198                    Timber::render( $templates, $context );
     199                    $output .= ob_get_contents();
     200                    ob_end_clean();
     201                }else{
     202                    ob_start();
     203                    ?>
     204                        <?php echo "<p>The Timber plugin is not active.<br> Activate Timber or set <code>timber='false'</code> in the short code</p>" ?>
     205                    <?php
     206                    $output .= ob_get_contents();
     207                    ob_end_clean();
     208                }
     209
    172210            }
    173211            $output .= $wrapperClose;
  • ac-custom-loop-shortcode/trunk/assets/css/ac_wp_custom_loop_styles.css

    r1957421 r2509295  
    1313    float: none;
    1414    display: block;
     15    padding: 0.25em 0.5em  !important;
     16}
     17.c-accl-post-thumb__heading{
     18   font-size: 1em !important;
     19    margin: 1em 0 !important;
     20}
     21
     22.c-accl-post-thumb__feature-image img{
     23    max-width: 100%;
     24    height: auto;
    1525}
    1626
  • ac-custom-loop-shortcode/trunk/loop-template.php

    r2206142 r2509295  
    77 */
    88
    9 $handle = 'ac_wp_custom_loop_styles';
    10 $list = 'enqueued';
    119
    12 if (! wp_script_is( $handle, $list )) {
    13     wp_register_style( 'ac_wp_custom_loop_styles', plugin_dir_url( __FILE__ ) . 'assets/css/ac_wp_custom_loop_styles.css', array(), '20181007' );
    14     wp_enqueue_style( 'ac_wp_custom_loop_styles' );
    15 }
    1610?>
    1711
  • ac-custom-loop-shortcode/trunk/readme.txt

    r2217622 r2509295  
    44Tags: shortcode, list post, list custom posts, timber, twig, custom post type
    55Requires at least: 4.6
    6 Tested up to: 5.3.2
    7 Stable tag: 1.4.3
     6Tested up to: 5.7
     7Stable tag: 1.5
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
     
    4040== Upgrade Notice ==
    4141
     42= 1.5 =
     43Updated Timber support.
     44
    4245= 1.4.3 =
    4346Fix release issues.
     
    5962
    6063== Changelog ==
     64
     65= 1.5 (2021-04-04) =
     66* Fix release issues.
    6167
    6268= 1.4.3 (2019-12-06) =
Note: See TracChangeset for help on using the changeset viewer.