Skip to content
PHP Logo

How can PHP be used to check the status of a page in a CMS like Contenido and adjust the navigation accordingly?

To check the status of a page in a CMS like Contenido and adjust the navigation accordingly, you can use PHP to retrieve the status of the current page and then conditionally display navigation links based on that status. This can be achieved by checking the status of the page in the database and then using conditional statements to show or hide navigation links based on the status.

php
// Assuming $pageId contains the ID of the current page
// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Check the status of the current page
$sql = "SELECT status FROM pages WHERE id = $pageId";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $status = $row["status"];
        // Adjust navigation based on page status
        if ($status == 'published') {
            // Display navigation links for published pages
            echo "<a href='#'>Link 1</a>";
            echo "<a href='#'>Link 2</a>";
        } else {
            // Display navigation links for unpublished pages
            echo "<a href='#'>Link 3</a>";
        }
    }
} else {
    echo "Page not found";
}

// Close database connection
$conn->close();