mirror of
https://github.com/cupcakearmy/liquet.git
synced 2024-12-22 16:16:25 +00:00
reader count with options menu
This commit is contained in:
parent
04c9ab3b6e
commit
cf0ecb26a0
@ -16,7 +16,7 @@ add_action( 'wp_enqueue_scripts', function () {
|
||||
|
||||
|
||||
add_action( 'admin_init', function () {
|
||||
add_settings_section( 'section', 'All Settings', null, 'theme-options' );
|
||||
add_settings_section( 'section-link', 'Links', null, 'theme-options' );
|
||||
|
||||
global $links;
|
||||
foreach ( $links as $link ) {
|
||||
@ -24,11 +24,19 @@ add_action( 'admin_init', function () {
|
||||
$id = $link . '_url';
|
||||
add_settings_field( $id, ucfirst( $link ) . ' Url', function () use ( $id ) { ?>
|
||||
<input type="text" name="<?= $id ?>" id="<?= $id ?>" value="<?= get_option( $id ); ?>"/>
|
||||
<?php }, 'theme-options', 'section' );
|
||||
<?php }, 'theme-options', 'section-link' );
|
||||
|
||||
register_setting( 'section', $id );
|
||||
register_setting( 'section-link', $id );
|
||||
}
|
||||
|
||||
add_settings_section( 'section-views', 'View counter', null, 'theme-options' );
|
||||
|
||||
add_settings_field( 'view_min', 'Show view counter if views are above:', function () { ?>
|
||||
<input type="text" name="view_min" id="view_min" value="<?= (int) get_option( 'view_min' ) ?>"/>
|
||||
<?php }, 'theme-options', 'section-views' );
|
||||
|
||||
register_setting( 'section-views', 'view_min' );
|
||||
|
||||
} );
|
||||
|
||||
function theme_settings_page() { ?>
|
||||
@ -36,7 +44,8 @@ function theme_settings_page() { ?>
|
||||
<h1>Theme Panel</h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields( 'section' );
|
||||
settings_fields( 'section-link' );
|
||||
settings_fields( 'section-views' );
|
||||
do_settings_sections( 'theme-options' );
|
||||
submit_button();
|
||||
?>
|
||||
|
@ -16,8 +16,28 @@ function getDates() {
|
||||
$modified = get_the_modified_date( ( $modified_year == $created_year ? 'F j' : null ) );
|
||||
|
||||
return [
|
||||
'created' => $created,
|
||||
'modified' => $modified,
|
||||
'different' => $created != $modified,
|
||||
'created' => $created,
|
||||
'modified' => $modified,
|
||||
'different' => $created != $modified,
|
||||
];
|
||||
}
|
||||
|
||||
function getCurrentPageViews() {
|
||||
if ( ! is_single() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$total = (int) do_shortcode( '[wpstatistics stat=pagevisits time=total]' );
|
||||
$min = (int) get_option( 'view_min' );
|
||||
|
||||
if ( $total < $min ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$approximated = round( $total / 1000, 1 );
|
||||
?>
|
||||
<div id="views">
|
||||
<b>~<?= $approximated ?>k readers</b>
|
||||
</div>
|
||||
<?
|
||||
}
|
@ -38,8 +38,9 @@ $dates = getDates();
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="flex item grow"></div>
|
||||
<div>
|
||||
<div class="text-align-right">
|
||||
<b>~<?= do_shortcode( '[rt_reading_time]' ); ?> min</b>
|
||||
<?= getCurrentPageViews() ?>
|
||||
</div>
|
||||
</div>
|
||||
<br><br>
|
||||
|
Loading…
Reference in New Issue
Block a user