Forum

Thread tagged as: Problem, Error, Twitter

Tweet App doesn't work on certain pages

The tweet app works on other pages but it doesn't work on my blog posts for some reason. I am using this code for both pages but the blog post pages return nothing.

<?php
    perch_twitter_get_latest(array(
        'count'=>2
    )); 
?>

post.html

<div class="section group">
    <div class="col span_3_of_4">
        <div class="sub-col span_4_of_4 paper">
            <a href="/"><i class="fa fa-home fa-lg"></i></a> > <a href="/blog">Blog</a> > <a href="<perch:blog id="postURL" type="hidden" />" rel="bookmark" class="p-name"><perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" /></a>
        </div>
    </div>
</div>
<div class="section group">
    <div class="col span_3_of_4 paper">
        <div class="sub-col span_4_of_4">
            <h2 class="title"><perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" /></h2>
            <span class="date"><i class="fa fa-calendar"></i><time class="dt-published" datetime="<perch:blog id="postDateTime" type="date" label="Date" time="true" format="Y-m-d H:i:s" divider-before="Meta information" />"><perch:blog id="postDateTime" type="date" time="true" format="%d %B %Y" /> </time></span>
            <perch:if exists="authorGivenName"><i class="fa fa-user"></i><perch:blog id="authorGivenName" type="hidden" /> <perch:blog id="authorFamilyName" type="hidden" /></perch:if>
            <hr/>
            <perch:blog id="postDescHTML" type="textarea" label="Post" order="2" editor="markitup" html="true" size="xxl autowidth" required="true" />
        </div>
    </div>
    <div class="col span_1_of_4 paper">
        <div class="sub-col span_4_of_4 sidebar">
            <h2>Latest Tweets</h2>
            <?php
                perch_twitter_get_latest(array(
                    'count'=>2
                )); 
            ?>
        </div>
    </div>
</div>
<div id="readtime" class="readtime">
    <svg xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="5.025 -9.3846 100.5 126.6921" xml:space="preserve">
        <g id="BLOCK_x5F_RECORD">
            <g>
                <path d="M95.942,43.094c3.67,25.501-14.021,49.172-39.521,52.842C30.9,99.626,7.24,81.935,3.56,56.424S17.57,7.253,43.081,3.563      v-7.14h13.34v7.14c6.41,0.58,16.321,4.69,21.271,8.82l5.051-5.05l9.43,9.42l-5.04,5.06      C91.252,26.753,95.362,36.674,95.942,43.094z M89.752,49.754c0-22.091-17.91-40.001-40.001-40.001S9.75,27.663,9.75,49.754      S27.66,89.755,49.751,89.755S89.752,71.845,89.752,49.754z" fill="#7ab5e1"/>
                <path d="M53.081,23.083v26.671c0,1.84-1.49,3.33-3.33,3.33c-1.84,0-3.33-1.49-3.33-3.33V23.083H53.081z" fill="#7ab5e1" />
            </g>
        </g>
    </svg>
    <div class="deets">
        <div class="num"></div>
    </div>
</div>
<perch:blog id="excerpt" type="textarea" label="Excerpt" textile="true" order="1" suppress="true" size="s" />
<perch:blog id="image" type="image" width="50" height="50" crop="true" suppress="true" />

post.php

<?php include('../perch/runtime.php'); ?>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
    <meta charset="utf-8">
    <title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?> - SANTINI.IO</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
    <?php perch_get_css(); ?>
    <link rel="icon" type="image/png" href="../img/icon.png">
    <link rel="stylesheet" href="blog-2.css" type="text/css" />
</head>
<body>
    <nav class="main-nav nav"  role="navigation" onclick="">
        <?php perch_pages_navigation(array(
                'from-path'            => '/',
                'levels'=>1
            ));
        ?>
    </nav>
    <div class="wrapper">

        <div class="post">

            <?php perch_blog_post(perch_get('s')); ?>

            <div class="section group">
                <div class="col span_3_of_4">
                    <div class="sub-col span_4_of_4 paper"> 
                    <?php perch_blog_post_comments(perch_get('s'));?>
                    </div>
                </div>
            </div>
            <div class="section group">
                <div class="col span_3_of_4">
                    <div class="sub-col span_4_of_4 paper">
                    <?php perch_blog_post_comment_form(perch_get('s')); ?>
                    </div>
                </div>
            </div>
        </div>

        <!--<nav class="sidebar">
            <h2>Archive</h2>

            <!--  By category listing 
            <?php perch_blog_categories(); ?>-->
            <!--  By tag 
            <?php perch_blog_tags(); ?>-->
            <!--  By year
            <?php perch_blog_date_archive_years(); ?> -->
            <!--  By year and then month - can take parameters for two templates. The first displays the years and the second the months see the default templates for examples 
            <?php perch_blog_date_archive_months(); ?>-->
        <!--</nav>-->


    <?php perch_get_javascript(); ?>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <!-- MENU -->
    <script>
        //  The function to change the class
        var changeClass = function (r,className1,className2) {
        var regex = new RegExp("(?:^|\\s+)" + className1 + "(?:\\s+|$)");
        if( regex.test(r.className) ) {
            r.className = r.className.replace(regex,' '+className2+' ');
        }
        else{
            r.className = r.className.replace(new RegExp("(?:^|\\s+)" + className2 + "(?:\\s+|$)"),' '+className1+' ');
        }
        return r.className;
        };  
        //  Creating our button for smaller screens
        var menuElements = document.getElementsByTagName("nav")[0];
        var htmlElement = document.getElementsByTagName("html")[0];
        menuElements.insertAdjacentHTML('afterBegin','<button type="button" id="menutoggle" class="navtoogle" aria-hidden="true"><span class="logo">SANTINI.IO</span></button>');
        // Adding a JS class when JS is activated
        changeClass(document.getElementsByTagName("html")[0], 'no-js', 'js');
        //  Toggle the class on click to show / hide the menu
        document.getElementById('menutoggle').onclick = function() {
            changeClass(this, 'navtoogle active', 'navtoogle');
        }
        // document click to hide the menu  credits to https://inpx.it/13WjECm
        document.onclick = function(e) {
            var mobileButton = document.getElementById('menutoggle'),
                buttonStyle =  mobileButton.currentStyle ? mobileButton.currentStyle.display : getComputedStyle(mobileButton, null).display;

            if(buttonStyle === 'block' && e.target !== mobileButton && new RegExp(' ' + 'active' + ' ').test(' ' + mobileButton.className + ' ')) {
                changeClass(mobileButton, 'navtoogle active', 'navtoogle');
            }
        }
    </script>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <script>
        document.addEventListener("DOMContentLoaded",function(){var e=!1;window.onscroll=function(){s=window.scrollY,s%5===0&&(displayReadTime(calcMinsLeft()),e||(document.getElementById("readtime").style.display="block",e=!0))}});var calcMinsLeft=function(){var e=document.getElementsByTagName("p"),n=[];for(i=0;i<e.length;i++){var t=e[i].getBoundingClientRect().bottom;t>0&&n.push(wordCount(e[i].innerHTML))}return readTime(n.addElements())},wordCount=function(e){return e.split(" ").length},readTime=function(e){return Math.round(e/190)},displayReadTime=function(e){document.getElementsByClassName("num")[0].innerHTML=e};Array.prototype.addElements=function(){var e=0;for(i=0;i<this.length;i++)"number"==typeof this[i]&&(e+=this[i]);return e};
    </script>
</body>
</html>
Nick Santini

Nick Santini 0 points

  • 6 years ago

I just realized that you can't have the php code in the html template. That seems so obvious now. Anyway, I have it fixed.