Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

thatgoodlookingguy on "Previous / Next Buttons in the same Category"

$
0
0

I've looked around the tutorials but they all seem to have different codes and stuff so I couldn't figure this problem out with my extremely limited knowledge. I'm using the Big Brother Theme.

I want to make my previous / next buttons go to the previous and next post in the same category and I also want the buttons to say previous chapter and next chapter.

This is my single.php

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package big-brother
 */

get_header(); ?>
	<?php if( function_exists( 'big_brother_the_breadcrumbs' ) ) : ?>
		<div class="breadcrumbs">
			<?php big_brother_the_breadcrumbs(); ?>
		</div>
	<?php endif; ?>
	<div class="primary content-area">
		<main id="main" class="site-main" role="main">

		<?php while ( have_posts() ) : the_post(); ?>
			<div class="article-wrapper">
				<?php get_template_part( 'content', 'single' ); ?>
			</div>

			<?php big_brother_content_nav( 'nav-below' ); ?>

			<?php
				// If comments are open or we have at least one comment, load up the comment template
				if ( comments_open() || '0' != get_comments_number() )
					comments_template();
			?>

		<?php endwhile; // end of the loop. ?>

		</main><!-- #main -->
	</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

and this is index.php

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package big-brother
 */

get_header(); ?>
	<div class="primary content-area">
		<main id="main" class="site-main" role="main">

		<?php if ( have_posts() ) : ?>

			<?php /* Start the Loop */ ?>
			<?php while ( have_posts() ) : the_post(); ?>

				<?php
					/* Include the Post-Format-specific template for the content.
					 * If you want to override this in a child theme, then include a file
					 * called content-___.php (where ___ is the Post Format name) and that
					 * will be used instead.
					 */
					get_template_part( 'content', get_post_format() );
				?>

			<?php endwhile; ?>

			<?php big_brother_content_nav( 'nav-below' ); ?>

		<?php else : ?>

			<?php get_template_part( 'no-results', 'index' ); ?>

		<?php endif; ?>

		</main><!-- #main -->
	</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Website: Christo Enzo


brveljkovic on "Custom Pagination, using global variable value inside a function"

$
0
0

hi all,
I need help with custom pagination function. I am trying to use max page number value from outside a function as a global variable. Check the code below. Have no idea why I can not make it to work. I have tried lots of stuff.

so I am trying to pass the value of $number_of_pages from outside the function to $max, which is inside the function.

/*-----------------------------------------------------------------------------------*/
$number_of_pages = $query->max_num_pages;
//echo $number_of_pages;
/*-----------------------------------------------------------------------------------*/
/* Numeric Pagination */
/*-----------------------------------------------------------------------------------*/

	function ct_numeric_pagination_boot() {
		/**	Add current page to the array */
		global $number_of_pages;
		//$paged = get_query_var('page') ? absint( get_query_var('page') ) : 1;
		$paged = $query->query['paged'];
		$max = $number_of_pages;
                .......

magnusb1 on "Trouble integrating external script"

$
0
0

I am trying to integrate an external script. I have added the script with the wp_enqueue_script function, and it seems to load. It is using an empty div to load into, and thats the problem. The page is missing the div. The company who made the script have no experience with wordpress, so no support from them. But they noticed the server sent the correct html, but it messed it up on the client side. Been trying different ways to get the div to show, but no luck yet. Some ideas?

The page is here
And here is one example on how it is supposed to look: here

hobhobuk on "Using multiple themes on alternative pages (portfolio etc)"

$
0
0

Hey,

So I am using this plugin (multiple themes) - https://wordpress.org/plugins/jonradio-multiple-themes/.

Plugin shows up fine on posts, not on pages however on the new WordPress.
However the advanced settings override the pages easily. I guess this could just be down to it not being updated in awhile.

However, currently I have it set to show posts on another theme, works great, pages works too, but I use a page as the homepage so want to avoid using that setting (i can only used advanced here, so setting all pages rather than individual, but fine for my need)

The theme I currently use, adds the 'portfolio' section to the wordpress menu, on this I cannot see the option to change theme for these pages. Is there anyway to add it to this area? Or a way I can add the code anywhere to make it work for these too?

Peixoto on "How to remove wp_add_inline_style css, and get list of inlined css?"

$
0
0

Hi,

I am developing a plugin and I would like to get a list of all inline css added by any plugin or theme via wp_add_inline_style, but can't seem to find the answer anywhere.

Let's say 20 plugins add something via wp_add_inline_style to wordpress.

How do I get a list of handles for what's queued to be inlined (it's not in the $wp_styles) and how do I selectively remove some inline css by handle name?

And also, how do I get the inline css code by handle so I can add it to a custom css static file?

Thanks

dileepraja on "My Core Functionality Not Working"

$
0
0

I have created plugin called send sms when activae the plugin everthing working fine tables are creating.But thing is in admin side WP_LIST_TABLE Not Working and as well ajax call request also not working.how to resolve this problem.Except single hosting it's not working but every where it's working fine

Bharat Karavadra on "Get 1 Random Post From Recent X Posts"

$
0
0

I wanted to display the featured image (post thumbnail) of one post from the most latest blog posts.

I didn’t want a plugin as the image was being displayed in some custom header background code… that at the top of the home page of this site.

I couldn’t find any code online that I could copy and paste and with a few similar recent and random post code snippets, I created my own PHP code snippet to display the featured image of one post from the latest X posts.

The code below uses the WordPress wp_get_recent_posts() function using appropriate arguments in the $arg variable to retrieve the most recent 30 posts.

Then, one random post is found that contains an featured image, as not all my posts contain a featured image.

Once the random post containing a featured image is found, the featured image URL is displayed.

You may wish to display other aspects of the post including the title and content, and these are contained the $onepost array which contains the following variables and their values for the one random post.

[ID]
[post_author]
[post_date]
[post_date_gmt]
[post_content]
[post_title]
[post_excerpt]
[post_status]
[comment_status]
[ping_status]
[post_password]
[post_name]
[to_ping]
[pinged]
[post_modified]
[post_modified_gmt]
[post_content_filtered]
[post_parent]
[guid]
[menu_order]
[post_type]
[post_mime_type]
[comment_count]
[filter]

Note that the featured image URL is not a variable in the $onepost array, and I used the WordPress function get_post_thumbnail_id() with the one random post ID to retrieve the one featured image URL.

$numberofposts = 30;
$args = array(
    'numberposts' => $numberofposts,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'post',
    'post_status' => 'publish',
    'suppress_filters' => true );
$recent_posts = wp_get_recent_posts( $args );
$randompost = rand(0,($numberofposts-1));
$onepost = $recent_posts[$randompost];
while ( !has_post_thumbnail($onepost['ID']) )
{
	$randompost = rand(0,($numberofposts-1));
	$onepost = $recent_posts[$randompost];
}
echo wp_get_attachment_url( get_post_thumbnail_id($onepost['ID']) );

meeshh on "logging in wordpress using NFC"

$
0
0

is there a way to simulate a login and authenticate using NFC?
let's say i have an NFC chip that stores a URL. can I have an encrypted query string in the URL and make it login to wordpress instead of the username and password?
is there any way to do that?


Carradee on "Widgets Working Fine EXCEPT Not Showing in Customizer"

$
0
0

I'm building a custom theme here.

The problem: Widget areas and widgets aren't showing in Customzer.
The weird part: They show up and work everywhere else.

I've:

  • verified that Customizer's working on default themes
  • logged out & back in
  • logged out, wiped my cache, & logged back in
  • deleted everything except the widget area registries from functions.php, and it still happened

So, as far as I can tell, it's a typo somewhere in my registry. It can't be a tab character, because stripping those out didn't fix it.

/*----------------------------------------------
	ADD WIDGET AREAS
----------------------------------------------*/

if(function_exists('register_sidebar')) {
// note: \r\n = standard for new line, but only double quotes read it (per http://stackoverflow.com/questions/1761051/difference-between-n-and-r)

function back2basics_widget_areas() {
 register_sidebar( array(
  'name' => 'Sidebar',
  'id' => 'sidebar',
  'description' => 'Widget area for you to put what you want in the sidebar.',
  'class' => '',
  'before_widget' => "<div class='widget' role='complementary'>\r\n",
  'after_widget' => "</div><!-- / .widget -->\r\n",
  'before_title' => "<h3 class='widget-title'>",
  'after_title' => "</h3>\r\n",
 ) );
 register_sidebar( array(
  'name' => 'Above Posts',
  'id' => 'main_top',
  'description' => 'Widget area above posts and pages, between navigation and post or page.',
  'class' => '',
  'before_widget' => "<div class='widget' role='complementary'>\r\n",
  'after_widget' => "</div><!-- / .widget -->\r\n",
  'before_title' => "<h3 class='widget-title'>",
  'after_title' => "</h3>\r\n",
 ) );
 register_sidebar( array(
  'name' => 'Below Posts',
  'id' => 'main_bottom',
  'description' => 'Widget area below posts and pages, before footer.',
  'class' => '',
  'before_widget' => "<div class='widget' role='complementary'>\r\n",
  'after_widget' => "</div><!-- / .widget -->\r\n",
  'before_title' => "<h3 class='widget-title'>",
  'after_title' => "</h3>\r\n",
 ) );
 register_sidebar( array(
  'name' => 'Footer Area',
  'id' => 'footer',
  'description' => 'Widget area for you to put what you want in the footer.',
  'class' => '',
  'before_widget' => "<div class='widget' role='complementary'>\r\n",
  'after_widget' => "</div><!-- / .widget -->\r\n",
  'before_title' => "<h3 class='widget-title'>",
  'after_title' => "</h3>\r\n",
 ) );
} // end function back2basics_widget_areas

add_action( 'widgets_init', 'back2basics_widget_areas' );

}  // end if (function_exists('register_sidebar'))

So do y'all see a typo that's slipping past my eye, or is there something else that I should check? (What else could keep them from even appearing in Customize options, although they display in the preview window?)

Thanks! :-)

Joel James on "Is it OK if I store individual transients options for each users?"

$
0
0

I would like to create individual temporary data for each users (registered users). I will be updating this continuously based on user's activity. Is it OK to use Transients API? What if there are 1000+ users? Any other recommended methods? I would like to have minimum database operations.

sa_ostad on "What is Best Delete Policy without foreign-key on Delete CASCADE"

$
0
0

I use MySQL as Database Management System , But it doesn't have foreign-key support by default configurations in WordPress.
So My question is in case of parent-child relationship what is the best solution when we want to delete parent records?

amurado on "Don't Show Post If No Featured Image Is Set"

$
0
0

I'm currently using the code below to show future posts that are not in a certain taxonomy. I was just wondering if there was also a way to not show posts at all if they don't have a featured image? They will still be available to view on their single page.

//Define your custom post type name in the arguments
$args = array('post_type' => 'movies', 'posts_per_page'=>'100', 'order'=>'ASC', 'date_query' => array( 'after' => "today" ), ) ;

$args['tax_query'] = array(
    array(
        'taxonomy' => 'feature',
        'terms' => array('movie-planner'),
        'field' => 'slug',
        'operator' => 'NOT IN',
    ),
);
query_posts($args);

//Define the loop based on arguments

$loop = new WP_Query( $args );

//Display the contents

while ( $loop->have_posts() ) : $loop->the_post();

nulldogmas on "excluding categories from get_the_category list"

$
0
0

I'm working on some php to generate a list of links based on the categories of the current post. So far I have this, which works great for most cases:

<?php $categories = get_the_category(); ?>
<nav>
<?php foreach ($categories as $category):?>
<a href="<?php echo 'https://www.nameoflinkedsite.com/' . $category->slug . '-tickets' ?>">
<?php echo $category->name . ' Tickets<br>' ?></a>
<?php endforeach; ?>
</nav>

My only problem: I need to exclude certain categories, and get_the_category() doesn't support this. I've tried a couple of solutions suggested elsewhere on the support forum, but none play nicely with the rest of my code. Any ideas?

You can view the test page for this code here:

http://www.fieldofschemes.com/1901/06/16/11239/ad-test-page/

milinpatel17 on "How to setup dynamic SMTP and contact form in WordPress via coding with built-in"

$
0
0

What I want to do is to have a custom contact form with SMTP which will send emails to the receipient and the From email address of that email will be the one which is taken as input from the form.

I have written this below code for contact form in contact.php:

<?php
// Please specify your Mail Server - Example: mail.example.com.
//ini_set("SMTP","localhost");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
//ini_set("smtp_port","25");
// Please specify the return address to use
//ini_set('sendmail_from', 'example@localhost');

// define variables and set to empty values
$sendernameErr = $emailErr = $websiteErr = $commentErr = "";
$sendername = $email = $comment = $website = "";
$sendernameErrFlag = $emailErrFlag = $websiteErrFlag = $commentErrFlag = 2;
//Set variable inputs from form.
  function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($referrer == "") {
        $referrer = "This page was accessed directly";
    }
  if (empty($_POST["sendername"])) {
    $sendernameErr = "Name is required";
    $sendernameErrFlag = 1;
  } else {
    $sendername = test_input($_POST["sendername"]);
    // check if sendername only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$sendername)) {
      $sendernameErr = "Only letters and white space allowed";
      $sendernameErrFlag = 1;
    } else {
      $sendernameErrFlag = 0;
  }
  }

  if (empty($_POST["email"])) {
    $emailErr = "Email is required";
    $emailErrFlag = 1;
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
      $emailErrFlag = 1;
    } else {
      $emailErrFlag = 0;
  }
  }

  if (empty($_POST["website"])) {
    $website = "";
  } else {
    $website = test_input($_POST["website"]);
    // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
    if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
      $websiteErr = "Invalid URL";
      $websiteErrFlag = 1;
    } else {
      $websiteErrFlag = 0;
  }
  }
  if (empty($_POST["comment"])) {
    $commentErr = "Comment is required";
    $commentErrFlag = 1;
  } else {
    $comment = test_input($_POST["comment"]);
    $commentErrFlag = 0;
  }
}
?>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo the_permalink();//htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES, "utf-8");?>">
    Name: <input type="text" name="sendername" value="<?php echo $sendername;?>">
  <span class="error">* <?php echo $sendernameErr;?></span>
  <br><br>
  E-mail: <input type="text" name="email" value="<?php echo $email;?>">
  <span class="error">* <?php echo $emailErr;?></span>
  <br><br>
  Website: <input type="text" name="website" value="<?php echo $website;?>">
  <span class="error"><?php echo $websiteErr;?></span>
  <br><br>
  Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
  <span class="error">* <?php echo $commentErr;?></span>
  <br><br>
  <input type="submit" name="submit" value="Submit">
</form>
<?php
/*
echo "<h2>Your Input:</h2>";
echo $sendername;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $headers;
*/
//print_r($_POST);
//echo $sendernameErrFlag . "<br/>" . $emailErrFlag . "<br/>" . $websiteErrFlag . "<br/>" . $commentErrFlag;
if($sendernameErrFlag == 0 && $emailErrFlag == 0 && $websiteErrFlag == 0 && $commentErrFlag == 0) {
    $headers = "From: <".$_POST["sendername"].">".$_POST["email"];
    mail("test@gmail.com","My subject",$comment,$headers);
    echo '<script>alert("Message sent successfully!!!");</script>';
} else {
    $sendernameErrFlag = $emailErrFlag = $websiteErrFlag = $commentErrFlag = 2;
}
?>

and for SMTP in functions.php

/* Email SMTP */
add_action( 'phpmailer_init', 'my_phpmailer_init' );
function my_phpmailer_init( PHPMailer $phpmailer ) {
    $phpmailer->IsSMTP();
    $phpmailer->Host = 'localhost';
    $phpmailer->Port = 25; // could be different
    //$phpmailer->Username = 'test@example.com'; // if required
    //$phpmailer->Password = 'password'; // if required
    $phpmailer->SMTPAuth = false; // if required
    //$phpmailer->SMTPSecure = 'tls'; // enable if required, 'tls' is another possible value
}

The email isn't working with Gmail SMTP credentials even if the SMTP credentials are correct. With localhost it is working but the headers are not setting up properly in the email. The From address of the email is default server address instead of the email address taken from the contact form.

How do I fix this?

Fact Maven Corp. on "Redirect "wlwmanifest.xml" to homepage"

$
0
0

As a non-blogger, I do not use any of the blogging functionality that comes prebuilt on WordPress.

I've removed the wlwmanifest.xml from the header using the following action:

remove_action('wp_head', 'wlwmanifest_link');

However, this only hides the XML from my header. If I were to visit some.web/wp-includes/wlwmanifest.xml, the page still exists. I would like to create a function to disable and redirect that page to the main website should it be accessed. I figure the logic would go something like this:

add_action( 'template_redirect', 'redirect' );
function redirect() {
    if( is_page( '/wlwmanifest.xml' ) )
    {
        wp_redirect( home_url( '/' ) );
        exit();
    }
}

If I could get some guidance on this, I would appreciate it.


axettone on "Scheduled events run only once and then they disappear"

$
0
0

Hi! This is the first time I'm developing a plugin. I need to set up a periodic job, so I used wp_schedule_event in the activation hook of the module (as described here: https://codex.wordpress.org/Function_Reference/wp_schedule_event). I'm using a plugin to track the scheduled jobs (something very similar to https://it.wordpress.org/plugins/cronjob-scheduler/screenshots/), and when I activate the module, the event appears correctly. If I fire the job manually, it disappears from the list. What kind of problem can do this?

Thank you in advance.

P.S.: I don't have the sources here now, but they're almost boilerplate. WordPress is clean, fresh-installed.

rockreyad on "How to Show User upload File in A Custom Page"

$
0
0

I need A Help Urgent About Wordpress.
I want to Show User Upload File In A custom Page Without A Plugin and With An upload bar.
Which will assist every image has a shortcode like this ex:[img id=1]. When user paste it in Anywhere, I means when user paste it in a post or a Comment box it will show the image..

An Another is...
A Font-end Notification Page.I means When A User Comment A post it will notify only the Author in a Custom Page and when admin change the User roles it will notify also..that's all..

vadiossalam on "spili in to 2 lines in plugin simple tooltip"

$
0
0

I have a small issue. Sometimes the tooltip text is split in two lines.
My max width is set to 500px. I have tested with larger width without results. The strange thing is that I have other tooltip with longer text and they do not split...
some ones offer this:
Zebra_Tooltip .Zebra_Tooltip_Message {
white-space: nowrap;
padding: 8px 9px !important; }

But this solution is not suitable for long text

Note that this happens when the text leads to a number
When the number is changed to the word do not split
When the text leads to a number, the maximum width is ignored
But in some cases it leads to a number, not split

knownocode on "Multisite BP install, comment notifier gives backend link but prefer post link"

$
0
0

I am running WordPress multisite on a new website with sub-directory sites. I have Buddypress running, and have setup a sub-site that is a user blog. The users post to the sub-site blog from the front end and everything is running smooth as it can be.

I have installed a notifier to notify users of comments on their blog posts. The notifier works good to relay to buddypress on the main-site with new notifications to the user of comments, however in the "Notifications" page the link that is given to click is to a backend page for comment moderation.

Instead of this backend page, I would like to direct users to the page that the comment is on (the post page). I have looked at WP User Frontend and their addon plugin "Comments Manager" and this demo does not look like it will help me to relay which post was commented on, as a frontend solution.

I also have tried to get the post ID (from the sub-site post) through a little php and relay it to create a proper link where it is echoed on the Notification page. The comment ID does echo properly to the link in the Notifications originally, however I do not know enough code to call the post ID from the sub-site blog post and have tried for two days now and failed over what I think is 1 line of code, so I thought it would be best to ask for help.

I have tried over and over, it looks and seems very simple but I just don't know any code or how to place it. If someone could please help me find a simple solution for this I would be most appreciative. Below is the code, I hope the post is not too big and also hope I post the code right, sorry in advance if the code isn't posted right or if it is too long......

[Large code excerpt removed by moderator per forum rules. Please use Pastebin or a Gist for all large code excerpts, they work better anyway.]

The code I am playing with that is changing the link is reposted below to show the exact line I'm playing with, again sorry for all the code, I just do not get 100% what I am looking at and just think someone who does know could look at the code and tell me where my troubles are. Thank you all for your help!!

if ( $comment->comment_approved == 1 ) {
			$link = get_comment_link ( $comment );
		} else {
			$link =admin_url( 'comment.php?action=approve&c=' . $comment_id );
		}

Fact Maven Corp. on "Remove rules from .htaccess through a plugin"

$
0
0

I've been able to add custom rules to my .htaccess through my plugin using the following function:

add_action( 'init', 'dsbl_htaccess' );

function dsbl_htaccess() {
            require_once( ABSPATH . '/wp-admin/includes/misc.php' );
            $rules = array();
            $rules[] = '<Files xmlrpc.php> # Disable XML-RPC';
            $rules[] = 'Order allow,deny';
            $rules[] = 'Deny from all';
            $rules[] = '</Files>';
            $rules[] = '';
            $rules[] = '<Files wlwmanifest.xml> # Disable Windows Live Writer';
            $rules[] = 'Order allow,deny';
            $rules[] = 'Deny from all';
            $rules[] = '</Files>';
            $htaccess_file = ABSPATH . '.htaccess';
            insert_with_markers( $htaccess_file, 'Fact Maven', ( array ) $rules );
        }

As a result, the following is added to the .htaccess:

# BEGIN Fact Maven
<Files xmlrpc.php> # Disable XML-RPC
Order allow,deny
Deny from all
</Files>

<Files wlwmanifest.xml> # Disable Windows Live Writer
Order allow,deny
Deny from all
</Files>
# END Fact Maven

However, I'd like to know how I can have these rules removed once the the plugin is deactivated. After doing some research online, I'm aware that I would have to use the register_deactivation_hook hook which will run a function when I deactivate a plugin.

But after that I am still lost on trying to figure out where to go after that. If someone could provide me with some guidance, I would appreciate it.

Viewing all 8245 articles
Browse latest View live




Latest Images