Online Business Card and Blog – Blog Page & Blog Post


The blog index with its pagination and the blogpost with its rating form are both displayed in the blog.php, depending on if $_GET is set (blogpost displayed) or not (index displayed). Here is the code:
<div class="ml-4">
<?php
// Wieviel Beiträge seit...
if($posts_gesamt > 1){
?>
<p class="text-right mx-4 mt-2">
<?php echo $posts_gesamt;?> Beiträge seit
<?php echo date("d.m.Y", strtotime($row["postDate"]));?>.
</p>
<?php
}else{
?>
<p class="text-right mx-4 mt-2">
<?php echo $posts_gesamt;?> Beitrag seit
<?php echo date("d.m.Y", strtotime($row["postDate"]));?>.
</p>
</div>
<?php
}//Ende
//Auswahl der Datensätze aus posts
$sql="SELECT postID, postDate, postTitle, postBild, postBildAlt, postMedia, postTube, postBody
FROM posts ORDER BY postDate DESC
LIMIT :erster, :anzahl";
//Bei Limit Special
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$abfrage=$db->prepare($sql);
$abfrage->bindParam(":erster",$start);
$abfrage->bindParam(":anzahl",$posts_pro_seite);
$abfrage->execute();
//lokale Zeitzone
setlocale(LC_TIME, "de_DE.utf8");
//Ausgabe - Vorschau der Bloposts
while($row = $abfrage->fetch()){
//Zeitstempel
$strtotime = strtotime($row["postDate"]);
//Wochentag
$strftimeA = strftime("%A", $strtotime);
//tag im Monat
$strftimee = strftime("%e", $strtotime);
//Monat ausgeschrieben
$strftimeB = strftime("%B", $strtotime);
//Jahr
$strftimeY = strftime("%Y", $strtotime);
//Stunden
$strftimeH = strftime("%H", $strtotime);
//Minuten
$strftimeM = strftime("%M", $strtotime);
//tags aus blogposts entfernen
$dnotags = strip_tags($row["postBody"]);
//Text kürzen für Post Vorschau
$b375 = substr($dnotags, 0, 375);
//position vor abgschnittenem Wort
$bstrr = strrpos($b375, " ");
// abgeschnittenes Wort entfernen
$btrim = substr($b375, 0, $bstrr);
//Durchschnittliche Bewertung pro Beitrag
$sql2="SELECT AVG(rateRating) AS durchschnitt
FROM pratings
WHERE postFID = :id
";
$postID = $row["postID"];
$abfrage2=$db->prepare($sql2);
$abfrage2->bindParam(":id",$postID);
$abfrage2->execute();
$row2 = $abfrage2->fetch();
$avg = number_format($row2["durchschnitt"], 1, ",", ".");
if($row2["durchschnitt"] == null){
$durchschnitt = "
<p class='ml-2'>noch nicht bewertet";
}else {
$durchschnitt = "
<p class='ml-2'>
<span class='text-danger'> $avg</span>/5 Punkten
<br>";
}
//Anzahl Bewertungen pro Beitrag
$sql3="SELECT COUNT(rateRating) AS anzahl
FROM pratings
WHERE postFID = :id
";
$abfrage3=$db->prepare($sql3);
$abfrage3->bindParam(":id",$postID);
$abfrage3->execute();
$row3 = $abfrage3->fetch();
$n =$row3["anzahl"];
if($n == null){
$anzahl = "
<br>";
}else {
$anzahl = "Bewertet von
<span class='text-danger'> $n </span> Besucher
<br>";
}
?>
<!-- Vorschauliste der Beiträge-->
<div class="card bg-dark m-4">
<div class="card-body ppost">
<div class="pimg mt-2 mx-2 rounded">
<img class="rounded-top" src="bilder/
<?php echo $row[" postBild "];?>" alt="
<?php echo $row[" postBildAlt "]?>" style="max-width:100%;">
<?php echo $durchschnitt?>
<?php echo $anzahl?>
<a href="blog.php?blogpost=
<?php echo $row[" postID "]?>#disqus_thread">
</a>
</p>
</div>
<div class="ml-2 ">
<h4 class="mt-0 pt-0">
<?php echo $row["postTitle"];?>
</h4>
<span class="text-danger">gepostet am:
<?php echo $strftimeA;?> den
<?php echo $strftimee;?>.
<?php echo $strftimeB;?>
<?php echo $strftimeY;?> um
<?php echo $strftimeH;?>h
<?php echo $strftimeM;?>.
</span>
<p class="text-justify">
<?php echo $btrim ?>...
<a href="blog.php?blogpost=
<?php echo $row[" postID "]?>"> Weiterlesen
</a>
</p>
</div>
</div>
</div>
<?php
}
}
//Pagination & Disqus
if(!isset($_GET["blogpost"])){
include("include/pagination.php");
}else{
$_GET["blogpost"] = $id;
?>
<div id="disqus_thread" class="mx-4"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
var disqus_config = function () {
this.page.url = "https://hempel-joel.at/blog.php?blogpost=
<?php echo $id;?>"; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier =
<?php echo $id;?>; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
this.page.title = "
<?php echo $title ;?>";
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://web-development-crypto-it.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
</noscript>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
include("include/foot.php");
?>
Online Business Card and Blog – blog.php
<ul class="pagination justify-content-center">
<?php
// Link zur vorherigen Seite
if($seite > 1){
$vorherige=$seite-1;
?>
<li class="page-item">
<a class="page-link bg-dark text-light" href="?seite=
<?php echo $vorherige;?>">
<i class="fas fa-angle-double-left">
</a>
</i>
</li>
<?php
}else{
?>
<li class="page-item disabled">
<a class="page-link bg-dark" href="#">
<i class="fas fa-angle-double-left">
</a>
</i>
</li>
<?php
}
//Anzahl derSeiten ermitteln und ausgeben
for($x=0; $x < $gesamtSeiten; $x++){
$seiten_nr = $x + 1;
if($seite == $seiten_nr){
?>
<li class="page-item active disabled">
<a class="page-link bg-dark" href="#">
<strong>
<?php echo $seiten_nr ;?>
</strong>
</a>
</li>
<?php
} else {
?>
<li class="page-item">
<a class="page-link bg-dark text-light" href="?seite=
<?php echo $seiten_nr;?>">
<?php echo $seiten_nr;?>
</a>
</li>
<?php
}
}
// Link zur nächsten Seite
if($seite < $gesamtSeiten){
$naechste=$seite+1;
?>
<li class="page-item">
<a class="page-link bg-dark text-light" href="?seite=
<?php echo $naechste;?>">
<i class="fas fa-angle-double-right">
</a>
</i>
</li>
<?php
}else{
?>
<li class="page-item disabled">
<a class="page-link bg-dark" href="#">
<i class="fas fa-angle-double-right">
</a>
</i>
</li>
<?php
}
?>
</ul>
pagination.php
<div class="ml-4">
<?php
// Wieviel Beiträge seit...
if($posts_gesamt > 1){
?>
<p class="text-right mx-4 mt-2">
<?php echo $posts_gesamt;?> Beiträge seit
<?php echo date("d.m.Y", strtotime($row["postDate"]));?>.
</p>
<?php
}else{
?>
<p class="text-right mx-4 mt-2">
<?php echo $posts_gesamt;?> Beitrag seit
<?php echo date("d.m.Y", strtotime($row["postDate"]));?>.
</p>
</div>
<?php
}//Ende
//Auswahl der Datensätze aus posts
$sql="SELECT postID, postDate, postTitle, postBild, postBildAlt, postMedia, postTube, postBody
FROM posts ORDER BY postDate DESC
LIMIT :erster, :anzahl";
//Bei Limit Special
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$abfrage=$db->prepare($sql);
$abfrage->bindParam(":erster",$start);
$abfrage->bindParam(":anzahl",$posts_pro_seite);
$abfrage->execute();
//lokale Zeitzone
setlocale(LC_TIME, "de_DE.utf8");
//Ausgabe - Vorschau der Bloposts
while($row = $abfrage->fetch()){
//Zeitstempel
$strtotime = strtotime($row["postDate"]);
//Wochentag
$strftimeA = strftime("%A", $strtotime);
//tag im Monat
$strftimee = strftime("%e", $strtotime);
//Monat ausgeschrieben
$strftimeB = strftime("%B", $strtotime);
//Jahr
$strftimeY = strftime("%Y", $strtotime);
//Stunden
$strftimeH = strftime("%H", $strtotime);
//Minuten
$strftimeM = strftime("%M", $strtotime);
//tags aus blogposts entfernen
$dnotags = strip_tags($row["postBody"]);
//Text kürzen für Post Vorschau
$b375 = substr($dnotags, 0, 375);
//position vor abgschnittenem Wort
$bstrr = strrpos($b375, " ");
// abgeschnittenes Wort entfernen
$btrim = substr($b375, 0, $bstrr);
//Durchschnittliche Bewertung pro Beitrag
$sql2="SELECT AVG(rateRating) AS durchschnitt
FROM pratings
WHERE postFID = :id
";
$postID = $row["postID"];
$abfrage2=$db->prepare($sql2);
$abfrage2->bindParam(":id",$postID);
$abfrage2->execute();
$row2 = $abfrage2->fetch();
$avg = number_format($row2["durchschnitt"], 1, ",", ".");
if($row2["durchschnitt"] == null){
$durchschnitt = "
<p class='ml-2'>noch nicht bewertet";
}else {
$durchschnitt = "
<p class='ml-2'>
<span class='text-danger'> $avg</span>/5 Punkten
<br>";
}
//Anzahl Bewertungen pro Beitrag
$sql3="SELECT COUNT(rateRating) AS anzahl
FROM pratings
WHERE postFID = :id
";
$abfrage3=$db->prepare($sql3);
$abfrage3->bindParam(":id",$postID);
$abfrage3->execute();
$row3 = $abfrage3->fetch();
$n =$row3["anzahl"];
if($n == null){
$anzahl = "
<br>";
}else {
$anzahl = "Bewertet von
<span class='text-danger'> $n </span> Besucher
<br>";
}
?>
<!-- Vorschauliste der Beiträge-->
<div class="card bg-dark m-4">
<div class="card-body ppost">
<div class="pimg mt-2 mx-2 rounded">
<img class="rounded-top" src="bilder/
<?php echo $row[" postBild "];?>" alt="
<?php echo $row[" postBildAlt "]?>" style="max-width:100%;">
<?php echo $durchschnitt?>
<?php echo $anzahl?>
<a href="blog.php?blogpost=
<?php echo $row[" postID "]?>#disqus_thread">
</a>
</p>
</div>
<div class="ml-2 ">
<h4 class="mt-0 pt-0">
<?php echo $row["postTitle"];?>
</h4>
<span class="text-danger">gepostet am:
<?php echo $strftimeA;?> den
<?php echo $strftimee;?>.
<?php echo $strftimeB;?>
<?php echo $strftimeY;?> um
<?php echo $strftimeH;?>h
<?php echo $strftimeM;?>.
</span>
<p class="text-justify">
<?php echo $btrim ?>...
<a href="blog.php?blogpost=
<?php echo $row[" postID "]?>"> Weiterlesen
</a>
</p>
</div>
</div>
</div>
<?php
}
}
//Pagination & Disqus
if(!isset($_GET["blogpost"])){
include("include/pagination.php");
}else{
$_GET["blogpost"] = $id;
?>
<div id="disqus_thread" class="mx-4"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
var disqus_config = function () {
this.page.url = "https://hempel-joel.at/blog.php?blogpost=
<?php echo $id;?>"; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier =
<?php echo $id;?>; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
this.page.title = "
<?php echo $title ;?>";
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://web-development-crypto-it.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
</noscript>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
include("include/foot.php");
?>