Wordpress

5 bookmark script options for wordpress

Creating a bookmark system for WordPress can range from simple solutions to more complex ones. Here are 5 different ideas and implementations you can consider. These examples assume some degree of PHP, MySQL, HTML, CSS, and JavaScript integration.

Option 1: Simple Bookmark System (PHP and MySQL Only)

// Add a bookmark
if (isset($_POST['bookmark'])) {
    $user_id = $_POST['user_id'];
    $post_id = $_POST['post_id'];
    $query = "INSERT INTO bookmarks (user_id, post_id) VALUES ('$user_id', '$post_id')";
    $connection->query($query);
}

// Display bookmarks
$query = "SELECT * FROM bookmarks WHERE user_id='current_user_id'";
$result = $connection->query($query);
while ($row = $result->fetch_assoc()) {
    echo "Post ID: " . $row['post_id'];
}

Option 2: Bookmarks using AJAX for dynamic updating

<button >



add_bookmark.php

<?php
$connection = new mysqli("localhost", "username", "password", "database");
$user_id = $_POST['user_id'];
$post_id = $_POST['post_id'];
$query = "INSERT INTO bookmarks (user_id, post_id) VALUES ('$user_id', '$post_id')";
$connection->query($query);
?>

Option 3: Using CSS to Display Bookmark Icon

<style>
.bookmark-icon {
    font-size: 24px;
    cursor: pointer;
    color: gray;
}
.bookmark-icon.active {
    color: gold;
}
</style>

<span class="bookmark-icon" >



Option 4: Interactive Bookmarks Using jQuery

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<button class="bookmark-btn" data-post-id="101">Bookmark</button>

<script>
$('.bookmark-btn').click(function() {
    const postId = $(this).data('post-id');
    $.post('add_bookmark.php', { post_id: postId }, function(response) {
        console.log(response);
    });
});
</script>

Option 5: Bookmarks using a WordPress widget

  • Create a widget file: bookmark-widget.php
  • PHP code for the widget:
<?php
class Bookmark_Widget extends WP_Widget {
    function __construct() {
        parent::__construct('bookmark_widget', __('Bookmark Widget', 'text_domain'), array('description' => __('A Widget to display bookmarks', 'text_domain')));
    }

    public function widget($args, $instance) {
        echo $args['before_widget'];
        echo '<button >



These options cover the basic approaches to implementing a bookmarking system in WordPress using various technologies. You can modify and extend them to suit your needs.

Victoria

Im just a girl who hanging around with her friends ;)

Share
Published by
Victoria

Recent Posts

PHP functions for working with MySQL: a detailed description

PHP provides a set of functions to work with MySQL databases. As of the more…

1 day ago

PHP pagination script from MySQL

Below is a PHP script that demonstrates how to implement pagination when displaying records from…

2 days ago

MySQL database table search script in PHP

Below is a simple PHP script that demonstrates how to search a MySQL database table…

2 days ago

Step-by-Step Guide to Moving Your WordPress Site to a New Domain

Transferring a WordPress site to a new domain involves several detailed steps to ensure that…

4 days ago

5 examples of creating client-server applications in C++

Creating client-server programs in C++ helps in understanding network programming and communication between applications over…

5 days ago

The robots.txt file settings

The robots.txt file is used by websites to communicate with web crawlers and bots about which parts…

1 week ago