


Beautify the website's top page link button: use the get_pages() method
If you followed my previous tutorial, you will now have a theme (or subtheme) on your site that contains links to the top-level pages in the header of your site.
I created a 26 child theme and this is what my links look like now:
In this tutorial, I'm going to show you how to add some CSS to your theme to make those links a little better. Let's start by removing bullets and adding floats.
Remove bullets and add floats
Open the theme's style sheet. If you created a child theme it will be empty, but if you are using your own theme I recommend adding this style in the section of your stylesheet that holds the header style.
Code review of output page link (if there is a page to be linked):
<ul class="top-level-page-links"> <?php // using a foreach loop, output the title and permalink for each page foreach ( $pages as $page ) { ?> <li class="page-link"> <a href="<?php echo get_page_link( $page->ID ); ?>"> <?php echo $page->post_title; ?> </a> </li> <? } ?> </ul>
This means we are targeting a ul
element with class top-level-page-links
and within it a li
element where # The ##page-link class is followed by the
a element (that is, the link).
ul.top-level-page-links { list-style: none; }
margin-left statement:
ul.top-level-page-links { list-style-type: none; margin-left: 0; }
.page-link { float: left; }
Add margins, padding and background
To make our link look like a button, we will add margins, padding, and a background to the link.
Add this to your stylesheet:
.page-link a { margin-right: 10px; padding: 0.5em 10px; background-color: #454545; }
When you refresh the screen, your buttons will look more like buttons:
Add hover effect
Now let's make these buttons more attractive.
Add two more declaration blocks to the stylesheet, making sure to add them after the declaration block of the link you just added:
.page-link a:link, .page-link a:visited { color: #fff; text-decoration: none; } .page-link a:hover, .page-link a:active { background-color: #dddddd; color: #454545; text-decoration: none; }
Let’s see how it looks on the page:
Summary
In this two-part tutorial, you learned how to create links to automatically generated top-level pages of your website, and then use CSS to style those links so that they look like buttons.
This gives you a nice, prominent way to get your visitors directly to these pages, which is useful if you want to ensure that a large number of visitors can access the top pages.
The above is the detailed content of Beautify the website's top page link button: use the get_pages() method. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Magnet link is a link method for downloading resources, which is more convenient and efficient than traditional download methods. Magnet links allow you to download resources in a peer-to-peer manner without relying on an intermediary server. This article will introduce how to use magnet links and what to pay attention to. 1. What is a magnet link? A magnet link is a download method based on the P2P (Peer-to-Peer) protocol. Through magnet links, users can directly connect to the publisher of the resource to complete resource sharing and downloading. Compared with traditional downloading methods, magnetic

Recently, many users have been asking the editor, how to download links starting with 115://? If you want to download links starting with 115://, you need to use the 115 browser. After you download the 115 browser, let's take a look at the download tutorial compiled by the editor below. Introduction to how to download links starting with 115:// 1. Log in to 115.com, download and install the 115 browser. 2. Enter: chrome://extensions/ in the 115 browser address bar, enter the extension center, search for Tampermonkey, and install the corresponding plug-in. 3. Enter in the address bar of 115 browser: Grease Monkey Script: https://greasyfork.org/en/

As part of the WeChat ecosystem, WeChat video accounts have gradually become an important promotion tool for content creators and merchants. Getting links to video accounts on this platform is crucial for sharing and disseminating content. The following will introduce in detail how to obtain the WeChat video account link and how to add product links to the video account to improve the dissemination effect of the content. 1. How to get the WeChat video account link? After posting a video on your WeChat video account, the system will automatically create a video link. Authors can copy the link after publishing to facilitate sharing and dissemination. After logging in to your WeChat video account, you can browse the homepage of your video account. On the home page, each video is accompanied by a corresponding link so you can copy or share it directly. 3. Search video account: Enter the video account name in the WeChat search box

Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

Do you frequently visit the same website at about the same time every day? This can lead to spending a lot of time with multiple browser tabs open and cluttering the browser while performing daily tasks. Well, how about opening it without having to launch the browser manually? It's very simple and doesn't require you to download any third-party apps, as shown below. How do I set up Task Scheduler to open a website? Press the key, type Task Scheduler in the search box, and then click Open. Windows On the right sidebar, click on the Create Basic Task option. In the Name field, enter the name of the website you want to open and click Next. Next, under Triggers, click Time Frequency and click Next. Select how long you want the event to repeat and click Next. Select enable

Link AppleNotes on iPhone using the Add Link feature. Notes: You can only create links between Apple Notes on iPhone if you have iOS17 installed. Open the Notes app on your iPhone. Now, open the note where you want to add the link. You can also choose to create a new note. Click anywhere on the screen. This will show you a menu. Click the arrow on the right to see the "Add link" option. click it. Now you can type the name of the note or the web page URL. Then, click Done in the upper right corner and the added link will appear in the note. If you want to add a link to a word, just double-click the word to select it, select "Add Link" and press

With the popularity of short video platforms, more and more creators are beginning to use video accounts to create and promote content. Video accounts can not only showcase personal talents, but also realize commercial monetization through product links. However, to add a link to a video account, certain conditions must be met. 1. What are the requirements for a video link? Video account authentication is a prerequisite for adding links to your video account. Currently, major short video platforms such as Douyin and Kuaishou provide certification services, which mainly include two types: personal certification and institutional certification. Personal certification requires the submission of real identity information, while institutional certification requires the provision of certification materials from relevant companies or organizations. After completing the authentication, users can add links to their video accounts to enhance the credibility and authority of their accounts. One of the video link

In macOS Sonoma and Safari 17, you can turn websites into "web apps," which can sit in your Mac's dock and be accessed like any other app without opening a browser. Read on to learn how it works. Thanks to a new option in Apple's Safari browser, it's now possible to turn any website on the internet you frequently visit into a standalone "web app" that lives in your Mac's dock and is ready for you to access at any time. The web app works with Mission Control and Stage Manager like any app, and can also be opened via Launchpad or SpotlightSearch. How to turn any website into
