简体   繁体   中英

WordPress Conditional if_page not working

my Conditional PHP is not working and i dont know why. Can you help me?

Here the Code:

<?php 
if( is_page(array('5279','4945') ))
{
echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_with_text.png"></a>';
}

elseif( is_page(array('5656','5668','5672','5677','5682','5690','5735','5738','5741','5744','5749','5752')))
{
echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_with_text_and_icon.png"></a>';
}
else
{
echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_without_text.png"></a>';
}
?>

But i need it in this way... (letters are the Pages ids)

For pages a,b,c,di need a own logo
For pages e,f,g,hi need a own logo
For pages j,k,l,mi need a own logo
and for Page n,o,p,qi need a own logo

Try this code, literally just tidied it slightly and removed the quotation marks round the page numbers.

<?php 
if(is_page(array(5279,4945) ))
{
    echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_with_text.png"></a>';
}
elseif(is_page(array(5656,5668,5672,5677,5682,5690,5735,5738,5741,5744,5749,5752)))
{
    echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_with_text_and_icon.png"></a>';
}
else
{
    echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_without_text.png"></a>';
}
?>

Just make sure you have the right pages. To do this go to pages in the dashboard and hover over the link to the page you want, you should see it shows the id number in the url, ie post=100. This is the id for that page and the one you will need to use. Using the id means that regardless of the page name, this code will always work for you.

An extreme test would also be using the below instead of the else

elseif(!is_page(array(5279,4945,5656,5668,5672,5677,5682,5690,5735,5738,5741,5744,5749,5752)))
{
    echo '<a href="http://www.example.de/"><img src="http://www.example.de/logo_without_text.png"></a>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM