Commit f0fbe4f7 by Muhammad Usman

hosting settings added

parent c35e5750
......@@ -12,9 +12,66 @@ function create_hosting_reviews()
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'hosting_reviews'),
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields')
'supports' => array( 'title', 'editor', 'thumbnail')
)
);
}
function vq_save_hosting_review($post_id)
{
if (isset($_POST['vq_review_hosting_company'])) {
$new_value = $_POST['vq_review_hosting_company'];
update_post_meta( $post_id, 'vq_review_hosting_company', $new_value );
}
}
function vq_hosting_company_metabox($post, $metabox)
{
$selected = get_post_meta( get_the_ID(), 'vq_review_hosting_company', true );
$hosting_companies = json_decode(get_option('vq_hosting_companies'));
if (!isset($hosting_companies)) {
$hosting_companies = [];
}
?>
<style>
.hosting-company-meta {
display: flex;
align-items: center;
}
.hosting-company-meta label {
width: 200px;
text-align: center;
font-weight: 500;
}
.hosting-company-meta select {
width: 200px;
height: 30px;
}
</style>
<div class="hosting-company-meta">
<label>Hosting Company: </label>
<select name="vq_review_hosting_company" id="voodoo_dropdown">
<?php foreach ($hosting_companies as $company): ?>
<option value="<?php echo $company->slug;?>" <?php echo $selected === $company->slug ? 'selected' : '' ?> ><?php echo $company->title; ?></option>
<?php endforeach; ?>
</select>
</div>
<?php
}
function vq_add_hosting_metaboxes()
{
add_meta_box( 'vq-hosting-company-metabox', __( 'Hosting Company'), 'vq_hosting_company_metabox', 'hosting_reviews' );
}
add_action('init', 'create_hosting_reviews');
add_action( 'add_meta_boxes', 'vq_add_hosting_metaboxes' );
add_action( 'save_post_hosting_reviews', 'vq_save_hosting_review' );
......@@ -28,7 +28,7 @@ function vq_recent_blogs_shortcode() {
</div>
<div class="hrBorder mt-0"></div>
<div class="d-flex j-content-center">
<a href="blog.html"><button type="button" class="btn blogReadMore mt-3">Read More</button></a>
<a href="'. get_the_permalink() .'"><button type="button" class="btn blogReadMore mt-3">Read More</button></a>
</div>
</div>
</div>';
......@@ -42,3 +42,49 @@ function vq_recent_blogs_shortcode() {
}
add_shortcode('recent-blogs', 'vq_recent_blogs_shortcode');
function vq_recent_reviews_shortcode() {
$the_query = new WP_Query( array(
'posts_per_page' => 3,
'post_type' => 'hosting_reviews'
));
$i = 1;
$str = "<div class='container'> <div class='row'>";
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$str .= '<div class="col-sm-4">
<div class="recentReviewBox white">
<img class="recentReviewImage" src="'. get_the_post_thumbnail_url() .'" alt="">
<div class="col-sm-12">
<div class="recentReviewHeading">
<h4>0'. $i++ .'</h4>
</div>
<div class="topBlog">
<h4>'. get_the_title() .'</h4>
</div>
<div class="post">
<p>'. get_the_excerpt() .'</p>
</div>
</div>
<div class="hrBorder mt-0"></div>
<div class="d-flex j-content-center">
<a href="'. get_the_permalink() .'"><button type="button" class="btn blogReadMore mt-3">Read More</button></a>
</div>
</div>
</div>';
endwhile;
else :
__('No News');
endif;
return $str .= '</div></div>';
}
add_shortcode('recent-reviews', 'vq_recent_reviews_shortcode');
......@@ -5,19 +5,156 @@
function vq_theme_settings_page()
{
?>
<div class="section panel">
<h1>Theme Options</h1>
<!-- <form method="post" enctype="multipart/form-data" action="options.php">-->
<div class="wrap">
<h1>Theme Settings</h1>
<form method="post" action="options.php">
<?php
// settings_fields('pu_theme_options');
// do_settings_sections('pu_theme_options.php');
settings_fields("section");
do_settings_sections("hosting-review-theme-options");
submit_button();
?>
<!-- <p class="submit">-->
<!-- <input type="submit" class="button-primary" value="--><?php //_e('Save Changes') ?><!--" />-->
<!-- </form>-->
</form>
</div>
<?php
}
add_action('admin_menu', 'vq_add_theme_setting_page');
function display_hosting_companies_table()
{
?>
<input style="display: none;" type="text" name="vq_hosting_companies" id="vq_hosting_companies" value="" />
<style>
.hosting-companies {
border-collapse: collapse;
text-align: center;
}
.hosting-companies th, .hosting-companies td {
padding: 5px;
text-align: center;
}
.hosting-companies tbody tr:nth-child(even) {
background: #fff;
}
.hosting-companies tbody tr:nth-child(odd) {
background: #ddd;
}
.hosting-companies tr.in-edit {
background: #b4b9be !important;
}
#cancel-company-btn {
display: none;
}
</style>
<table>
<tr>
<td>Title: <input type="text" id="new-company-title"></td>
<td>Slug: <input type="text" id="new-company-slug"></td>
<td><button onclick="saveCompany()" type="button" id="add-company-btn">Add</button></td>
<td><button onclick="resetData()" type="button" id="cancel-company-btn">Cancel</button></td>
</tr>
<tr>
</tr>
</table>
<table class="hosting-companies">
<thead>
<tr>
<th>Title</th>
<th>Slug</th>
<th></th>
</tr>
</thead>
<tbody id="hosting-companies-body">
</tbody>
</table>
<script>
var hostingCompaniesData = <?php echo get_option('vq_hosting_companies'); ?>;
if (!hostingCompaniesData) {
hostingCompaniesData = [];
}
var inEditIndex = -1;
var titleEl = document.getElementById('new-company-title');
var slugEl = document.getElementById('new-company-slug');
var cancelEl = document.getElementById('cancel-company-btn');
function saveCompany() {
if (!titleEl.value || !slugEl.value) {
return alert('Please fill all fields');
}
if (inEditIndex > -1) {
hostingCompaniesData[inEditIndex].title = titleEl.value;
hostingCompaniesData[inEditIndex].slug = slugEl.value;
} else {
hostingCompaniesData.push({title: titleEl.value, slug: slugEl.value});
}
populateTable();
resetData();
}
function editCompany(index) {
resetData();
inEditIndex = index;
titleEl.value = hostingCompaniesData[index].title;
slugEl.value = hostingCompaniesData[index].slug;
document.getElementById('add-company-btn').innerText = 'Update';
document.getElementById(`hosting-company-${index}`).classList.add('in-edit');
document.getElementById('cancel-company-btn').style.display = 'block';
}
function deleteCompany(index) {
if (confirm('Are you you want to remove this company?')) {
hostingCompaniesData.splice(index, 1);
populateTable();
resetData();
}
}
function resetData() {
if (inEditIndex > -1) {
document.getElementById(`hosting-company-${inEditIndex}`).classList.remove('in-edit');
}
titleEl.value = '';
slugEl.value = '';
inEditIndex = -1;
document.getElementById('cancel-company-btn').style.display = 'none';
}
function populateTable() {
var tableBody = document.getElementById('hosting-companies-body');
tableBody.innerHTML = '';
hostingCompaniesData.forEach(function(company, index) {
var row = `<tr id="hosting-company-${index}">`;
row += `<td>${company.title}</td>`;
row += `<td>${company.slug}</td>`;
row += `<td><a style="cursor:pointer;" onclick="editCompany(${index})">Edit</a> &nbsp;&nbsp; <a style="cursor:pointer;" onclick="deleteCompany(${index})"> Delete</a></td>`;
row += `</tr>`;
tableBody.innerHTML += row;
});
resetData();
document.getElementById('vq_hosting_companies').value = JSON.stringify(hostingCompaniesData);
}
populateTable();
</script>
<?php
}
function vq_display_theme_panel_fields()
{
add_settings_section("section", "Hosting Companies", null, "hosting-review-theme-options");
add_settings_field("vq_hosting_companies", "Add Hosting Company", "display_hosting_companies_table", "hosting-review-theme-options", "section");
register_setting("section", "vq_hosting_companies");
}
add_action("admin_init", "vq_display_theme_panel_fields");
......@@ -28,7 +28,7 @@ Template Name: Blog Page
<div class="col-sm-12">
<img class="blogImage" src="<?php echo get_the_post_thumbnail_url();?>">
<div class="blogSingle">
<h3><?php the_title(); ?> </h3>
<a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?> </h3></a>
</div>
<div class="d-flex spaceBetween">
<div class="singleBox r-margin">
......@@ -93,28 +93,3 @@ Template Name: Blog Page
<?php
get_footer();
//<?php
// $loop = new WP_Query( array( 'post_type' => 'hosting_reviews', 'paged' => true ) );
// if ( $loop->have_posts() ) :
// while ( $loop->have_posts() ) : $loop->the_post(); ?>
<!-- <div class="pindex">-->
<!-- --><?php //if ( has_post_thumbnail() ) { ?>
<!-- <div class="pimage">-->
<!-- <a href="--><?php //the_permalink(); ?><!--">--><?php //the_post_thumbnail(); ?><!--</a>-->
<!-- </div>-->
<!-- --><?php //} ?>
<!-- </div>-->
<!-- --><?php //endwhile;
// if ( $loop->max_num_pages > 1 ) : ?>
<!-- <div id="nav-below" class="navigation">-->
<!-- <div class="nav-previous">--><?php //next_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'domain' ) ); ?><!--</div>-->
<!-- <div class="nav-next">--><?php //previous_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'domain' ) ); ?><!--</div>-->
<!-- </div>-->
<!-- --><?php //endif;
// endif;
// wp_reset_postdata();
//?>
......@@ -144,8 +144,6 @@ function vq_theme_customize_register( $wp_customize ) {
)
);
// ..repeat ->add_setting() and ->add_control() for mytheme_company-division
}
add_action( 'customize_register', 'vq_theme_customize_register' );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment