1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

display a list/content on a specific blog article page using php

Discussion in 'PHP' started by Ian Haney, Jan 13, 2019.

  1. #1
    I have got a blog main page and the actual blog articles pages that are stored in a database table and uses a main blog index.php page where all the blog articles are displayed and then the individual blog articles are displayed on a page called viewpost.php and it gets the relevant blog article from the database using id/postSlug so the urls are SEO friendly and not something like id=1 and so on.

    I am looking to display some content that uses HTML coding on a specific blog article using php
    SEMrush
    I thought I could do something like the following but does not display anything

    
    <?  if($row['postSlug'] == 'fake-antivirus-software-scam') { ?>
            <div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>
            <?  } ?>
    
    Code (markup):
    I have tried the following as well but is not displaying nothing of what I want

    
    <?php if ($postID=="24") echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>'; ?>
    
    Code (markup):
    I have tried to look on Google to find similar coding for what I am looking to do but not had much joy yet, can anyone help please. Thank you in advance
     
    Ian Haney, Jan 13, 2019 IP
    SEMrush
  2. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #2
    I have tried both of them ways and does not display the html list

    'fake-antivirus-software-scam' is the postSlug of the blog article so the url is www.it-doneright.co.uk/blog/fake-antivirus-software-scam
     
    Ian Haney, Jan 13, 2019 IP
  3. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #3
    I have just managed to solve it by using the following code

    
    <?php if($row['postID'] == '24') echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>'; ?>
    
    Code (markup):
     
    Ian Haney, Jan 13, 2019 IP
  4. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #4
    I now need to get it to show on more than one specific blog post, I tried the following code but that makes it appear on all the blog posts

    
    if($row['postID'] == '24' || '27')
    
    Code (markup):
    Sorry managed to get this working with the following code

    
    <?php if($row['postID'] == '24' || $row['postID'] == '28')
    
    Code (markup):
    Now I need help with a else statement as on some other specific blog posts, I want to display another bit of content/coding. I tried with the following but get a blank white page, I added in php error reporting but shows no errors, just a blank white page, the coding I currently have is below

    
    <?php if($row['postID'] == '24' || $row['postID'] == '28') { echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../virus-removal-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>';
               
            } elseif ($row['postID'] == '27' || $row['postID'] == '29') { echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repaid-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>'; ?>
    
    Code (markup):
     
    Last edited: Jan 13, 2019
    Ian Haney, Jan 13, 2019 IP
  5. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #5
    Thought I was winning, the php code below is causing the blank white page, looks like a code error within the code below, can anyone help me correct it please

    
    <?php if($row['postID'] == '24' || $row['postID'] == '28') { echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../virus-removal-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>';
               
            } elseif (($row['postID'] == '27' || $row['postID'] == '29')) { echo '<div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>'; ?>
    
    Code (markup):
     
    Ian Haney, Jan 13, 2019 IP
  6. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #6
    Update: I have sorted the blank white page issue with the amended coding below but now I am unsure how to put multiple id's into the coding, for example I want the article appearing on postID 24 to also appear on postID 28

    
    <?php if ($row['postID'] == "24") { ?>
    
    <div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../virus-removal-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>
    
    <?php } else if ($row['postID'] == "27") { ?>
    
    <div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>
    
    <? } ?>
    
    Code (markup):
     
    Ian Haney, Jan 14, 2019 IP
  7. Ian Haney

    Ian Haney Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #7
    I have managed to solve the multiple ids, I altered the code to be a array so now looks like the following and works perfect

    
    <?php if (in_array($row['postID'], array(24, 28, 34))) { ?>
    
    <div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../virus-removal-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>
    
    <?php } else if (in_array($row['postID'], array(27, 29))) { ?>
    
    <div class="article">
                    <div class="text-center">
                        <div class="col-md-12">
                    <h3 class="h-lg text-center">Areas <span class="color">We</span> Cover</span></h3>
                        </div>
                   
                    <div class="col-md-6">   
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-basildon"><span>Basildon</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-services-pitsea"><span>Pitsea</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-laindon"><span>Laindon</span></a></li>
                    </ul>
                    </div>
                       
                        <div class="col-md-6">
                    <ul class="areaslist">
                    <li class="areasitem"><a href="../computer-repair-langdon-hills"><span>Langdon Hills</span></a></li>
                    <li class="areasitem"><a href="../computer-repair-wickford"><span>Wickford</span></a></li>
                    </ul>
                        </div>
                    </div>
                </div>
    
    <? } ?>
    
    Code (markup):
     
    Ian Haney, Jan 14, 2019 IP