-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,652 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# HTML Sitemap Plugin | ||
|
||
**HTML Sitemap** is a WordPress plugin that automatically generates a dynamic HTML sitemap for your website. This sitemap organizes your site's content by year, month, and day, making it easier for visitors and search engines to navigate and index your site effectively. | ||
|
||
 | ||
|
||
## Features | ||
|
||
- **Automatic Sitemap Generation:** Creates and updates an HTML sitemap page upon activation, and daily as content changes. | ||
- **Date-Based Organization:** Structures posts by year, month, and day for intuitive browsing. | ||
- **Caching Mechanism:** Implements caching to optimize performance and reduce database queries. | ||
- **Scheduled Updates:** Uses WordPress cron to schedule daily sitemap updates. | ||
|
||
## Installation | ||
|
||
### Using Composer | ||
|
||
To install the plugin via Composer, follow these steps: | ||
|
||
1. **Add the Repository:** | ||
- Open your project's `composer.json` file. | ||
- Add the following under the `repositories` section: | ||
|
||
```json | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/xwp/sitemap-html" | ||
} | ||
] | ||
``` | ||
|
||
2. **Require the Plugin:** | ||
- Run the following command in your terminal: | ||
|
||
```bash | ||
composer require xwp/sitemap-html | ||
``` | ||
|
||
3. **Activate the Plugin:** | ||
- Once installed, activate the plugin through the 'Plugins' menu in WordPress. | ||
|
||
### Manual Installation | ||
|
||
1. **Download the Plugin:** | ||
- Download the `sitemap-html` plugin folder. | ||
|
||
2. **Upload the Plugin:** | ||
- Upload the `sitemap-html` folder to the `/wp-content/plugins/` directory of your WordPress installation. | ||
|
||
3. **Activate the Plugin:** | ||
- Activate the plugin through the 'Plugins' menu in WordPress. | ||
|
||
## Usage | ||
|
||
Upon activation, the HTML Sitemap plugin will: | ||
|
||
1. **Create a Sitemap Page:** | ||
- Automatically create a page with the slug `sitemap` and assign it the HTML Sitemap template. | ||
- If a page with the slug `sitemap` already exists, the plugin will append to its content the `[sitemap-html-dated]` shortcode. | ||
- The rewrite rules are flushed. | ||
|
||
**WordPress VIP**: On this hosting environment, flushing the rewrite rules requires a manual action: | ||
Go to Settings > Permalinks, and hit Save Changes. | ||
|
||
2. **Generate Sitemap Content:** | ||
- Organizes and displays published posts by year, month, and day on the sitemap page. | ||
|
||
3. **Automatic Updates:** | ||
- Schedules daily updates to ensure the sitemap remains current with new or updated content. | ||
|
||
## Uninstallation | ||
|
||
When uninstalling the plugin: | ||
|
||
1. **Manual Cleanup (if necessary):** | ||
- You can manually remove the sitemap page, if desired. | ||
|
||
## Frequently Asked Questions | ||
|
||
**Q: Can I include custom post types in the sitemap?** | ||
**A:** Yes! By default, the plugin includes only the `post` post type. You can modify the `sitemap_html_post_types` filter to include additional post types as needed. | ||
|
||
**Q: Do I need to manually flush permalinks after activation?** | ||
**A:** No. The plugin automatically flushes permalinks after creating or updating the sitemap page upon activation, ensuring that rewrite rules are up to date without manual intervention. | ||
|
||
**Q: How does caching work in the plugin?** | ||
**A:** The plugin caches sitemap data to optimize performance and reduce database queries. It utilizes WordPress options or large options if available (`wlo_update_option` and `wlo_get_option`) for efficient data handling. | ||
|
||
**Q: Is there a way to exclude specific posts or pages from the sitemap?** | ||
**A:** Currently, the plugin includes all published posts by default. To exclude specific content, you can extend the plugin's functionality by modifying the query parameters within the `Posts` class. Contributing custom filters to the plug-in is also welcomed. | ||
|
||
## Changelog | ||
|
||
### 1.0.0 | ||
- Initial release. | ||
|
||
## Support | ||
|
||
If you encounter any issues or have questions about the HTML Sitemap plugin, please reach out to our support team or visit our [GitHub repository](https://github.com/xwp/sitemap-html). | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please follow the standard GitHub workflow: | ||
|
||
1. Fork the repository. | ||
2. Create a feature branch. | ||
3. Commit your changes. | ||
4. Push to the branch. | ||
5. Open a pull request. | ||
|
||
Please ensure that your code adheres to the [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/). | ||
|
||
## License | ||
|
||
This plugin is licensed under the [GNU General Public License v2 or later](https://www.gnu.org/licenses/gpl-2.0.html). | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* Breadcrumbs */ | ||
|
||
#sitemap-html-breadcrumbs { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin: 1rem 0; | ||
} | ||
|
||
#sitemap-html-breadcrumbs:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
#sitemap-html-breadcrumbs ol { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 1ex; | ||
justify-content: center; | ||
align-items: center; | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
} | ||
|
||
#sitemap-html-breadcrumbs li { | ||
display: inline; | ||
} | ||
|
||
#sitemap-html-breadcrumbs a { | ||
font-weight: bold; | ||
white-space: nowrap; | ||
text-decoration: none; | ||
} | ||
|
||
#sitemap-html-breadcrumbs a:hover, | ||
#sitemap-html-breadcrumbs a:focus { | ||
text-decoration: none; | ||
} | ||
|
||
#sitemap-html-breadcrumbs a:hover span, | ||
#sitemap-html-breadcrumbs a:focus span { | ||
text-decoration: underline; | ||
} | ||
|
||
#sitemap-html-breadcrumbs a::before { | ||
font-weight: normal; | ||
content: '»'; | ||
padding-right: 1ex; | ||
color: inherit; | ||
} | ||
|
||
#sitemap-html-breadcrumbs li:first-child a { | ||
font-weight: normal; | ||
} | ||
|
||
#sitemap-html-breadcrumbs li:first-child a::before { | ||
content: none; | ||
} | ||
|
||
/* Sitemap */ | ||
|
||
#sitemap-html { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 1rem; | ||
width: 100%; | ||
container-type: inline-size; | ||
} | ||
|
||
#sitemap-html ul { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
/* Sitemap - All Years months */ | ||
|
||
#sitemap-html .sitemap-html__year { | ||
flex: 1 0 9rem; | ||
min-width: 9rem; | ||
max-width: calc( ( 100% - 4rem ) / 4 ); | ||
} | ||
|
||
@container (max-width: 40rem) { | ||
#sitemap-html .sitemap-html__year { | ||
max-width: calc( (100% - 3rem) / 3 ); | ||
} | ||
} | ||
|
||
@container (max-width: 30rem) { | ||
#sitemap-html .sitemap-html__year { | ||
max-width: calc( (100% - 2rem) / 2 ); | ||
} | ||
} | ||
|
||
@media (max-width: 40rem) { | ||
#sitemap-html .sitemap-html__year { | ||
max-width: calc( (100% - 3rem) / 3 ); | ||
} | ||
} | ||
|
||
/* 2 Columns */ | ||
@media (max-width: 30rem) { | ||
#sitemap-html .sitemap-html__year { | ||
max-width: calc( (100% - 2rem) / 2 ); | ||
} | ||
} | ||
|
||
/* Sitemap - Month's days */ | ||
|
||
#sitemap-html .sitemap-html__month { | ||
width: 100%; | ||
} | ||
|
||
#sitemap-html .sitemap-html__month ul { | ||
display: grid; | ||
grid-auto-flow: column; | ||
grid-auto-columns: minmax(9rem, 1fr); | ||
grid-template-rows: repeat(auto-fill, minmax(2em, auto)); | ||
column-gap: 1rem; | ||
min-height: 32em; | ||
} | ||
|
||
/* On bigger screens, reduce the height of the month's days, as more columns can be fit. */ | ||
@media ( min-width: 600px ) { | ||
#sitemap-html .sitemap-html__month ul { | ||
min-height: 17em; | ||
} | ||
} | ||
|
||
@container ( min-width: 600px ) { | ||
#sitemap-html .sitemap-html__month ul { | ||
min-height: 17em; | ||
} | ||
} | ||
|
||
#sitemap-html .sitemap-html__month li { | ||
line-height: 2em; | ||
break-inside: avoid; | ||
} | ||
|
||
/* Sitemap - Day's posts */ | ||
|
||
#sitemap-html .sitemap-html__day { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "xwp/sitemap-html", | ||
"description": "HTML Sitemap is a WordPress plugin that automatically generates a dynamic HTML sitemap for your website.", | ||
"type": "wordpress-plugin", | ||
"require": { | ||
"php": ">=7.2", | ||
"composer/installers": "~1.0" | ||
}, | ||
"license": "GPL-2.0-or-later", | ||
"authors": [ | ||
{ | ||
"name": "XWP", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/xwp/sitemap-html/issues", | ||
"source": "https://github.com/xwp/sitemap-html" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/xwp/sitemap-html" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace SitemapHtml; | ||
|
||
/** | ||
* Helper for working with dates. | ||
*/ | ||
class Date { | ||
|
||
/** | ||
* Reference UNIX timestamp. | ||
* | ||
* @var integer | ||
*/ | ||
protected $timestamp; | ||
|
||
/** | ||
* Create a sitemap date instance. | ||
* | ||
* @param integer $timestamp Reference timestamp. | ||
*/ | ||
public function __construct( $timestamp ) { | ||
$this->timestamp = $timestamp; | ||
} | ||
|
||
/** | ||
* Extract a numeric date/time component from a timestamp. | ||
* | ||
* @param string $component Component symbol such as d, Y, m, etc. | ||
* | ||
* @return integer | ||
*/ | ||
protected function extract( $component ) { | ||
return intval( gmdate( $component, $this->timestamp ) ); | ||
} | ||
|
||
/** | ||
* Get the numerical day of month. | ||
* | ||
* @return integer | ||
*/ | ||
public function day() { | ||
return $this->extract( 'd' ); | ||
} | ||
|
||
/** | ||
* Get the numerical month. | ||
* | ||
* @return integer | ||
*/ | ||
public function month() { | ||
return $this->extract( 'm' ); | ||
} | ||
|
||
/** | ||
* Get the numeric year. | ||
* | ||
* @return integer | ||
*/ | ||
public function year() { | ||
return $this->extract( 'Y' ); | ||
} | ||
|
||
/** | ||
* Create a timestamp out of year, month and day components. | ||
* | ||
* @param integer $year Year. | ||
* @param integer $month Month. | ||
* @param integer $day Day. | ||
* | ||
* @return integer|false | ||
*/ | ||
public static function make( $year, $month = 1, $day = 1 ) { | ||
$month = is_numeric( $month ) ? intval( $month ) : 1; | ||
$day = is_numeric( $day ) ? intval( $day ) : 1; | ||
|
||
return strtotime( | ||
sprintf( | ||
'%04d-%02d-%02d', | ||
intval( $year ), | ||
intval( $month ), | ||
intval( $day ) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Pad a number with leading zeros. | ||
* | ||
* @param integer $number Number. | ||
* | ||
* @return string | ||
*/ | ||
public static function pad( $number ) { | ||
return sprintf( '%02d', intval( $number ) ); | ||
} | ||
} |
Oops, something went wrong.