Basically, my Wordpress site has about 50,000 unique posts, I want to incorporate asdfly to the next/previous post link buttons. I want to insert asdfly/527275432/ before the next/previous url, so it would look like this..
asdfly/527274352/www.google.com/previous
(Previous Post Title)
asdfly/527274352/www.google.com/next
(Next Post Title)
Is there any possible way to do this? I tried with the template but I couldn't figure it out.. Someone had managed to help me before but the same code doesn't work on the new site I'm working with, this is a different theme so maybe that's why. Here is what my current next and previous post buttons are/look like:
<div class="right-side">
<?php
if( $prev_link != NULL )
echo $prev_link . "<i title='Last Episode' class='playerleft tooltips fa fa-angle-double-left'> </i></a>";?>
<a class="tooltips" title='View all <?php echo $name; ?> Episodes' href='<?php echo $series_link; ?>'><i class="allepisodes fa fa-sort-amount-asc"></i></a>
<?php
if( $next_link != NULL )
echo $next_link . "<i title='Next Episode'class='playerright tooltips fa fa-angle-double-right'> </i></a>"; ?>
</div> <!-- End of right side -->
This is the previous code someone has gotten for me, however it doesn't work on this website:
function modify_prev_link( $link ) {
$link = str_replace( "href=\"http://", "href=\"http://asdf.ly/527274352/", $link );
return $link;
}
add_filter( 'previous_post_link', 'modify_prev_link' );
function modify_next_link( $link ) {
$link = str_replace( "href=\"http://", "href=\"http://asdf.ly/527274352/", $link );
return $link;
}
add_filter( 'next_post_link', 'modify_next_link' );
An example of what this would look like on the page:
http://animewolf.tv/anime/yama-no-susume-2nd-season-episode-21-subbed/
If you refer to the buttons on the right side below the video player, I want to modify them so that the adfly code will come before the url of the next episode.
I've been going crazy trying to find an answer for this, if anyone knows of one I will tip you $5 paypal, just leave me your pp after I've confirmed it's worked :) just a little side note to show my appreciation.
Thanks
Not sure if this will work, but tested on wordpress with different template.
I tried with your button link which don't work on my templates.
Changed code for button link (most likely on single.php file)
<?php next_post_link( '%link', "<i title='Last Episode' class='playerleft tooltips fa fa-angle-double-left'> </i>", TRUE ); ?>
<a class="tooltips" title='View all <?php echo $name; ?> Episodes' href='<?php echo $series_link; ?>'><i class="allepisodes fa fa-sort-amount-asc"></i></a>
<?php previous_post_link( '%link', "<i title='Next Episode'class='playerright tooltips fa fa-angle-double-right'> </i></a>", TRUE ); ?>
edit on your function.php file (changing function) working fine.
Hope it help.
:)
Related
this is my second question here, first one was resolved quite quickly and I appreciate any help I get. Here's the thing:
I have a folder views in which I have a folder named _global in which I have my beforeContent.php and afterContent.php those are my header and footer of actual Web pages. The main content in my pages is set in other view folders and I have no problem there.
I have this script in my beforeContent.php (this one shows my navbar):
<?php if (Session::exists('user_id')): ?>
<?php include 'app/views/_global/menu-session.php'; ?>
<?php else: ?>
<?php include 'app/views/_global/menu-no-session.php'; ?>
<?php endif; ?>
basically, if a user is logged in, it will show menu-session.php, if there's no user logged in, it will show menu-no-session.php.
my menu-session has this in it:
<ul>
<li><a <?php if ($FoundRoute['Controller'] == 'Main') echo
'class="active";'?> href="<?php echo Configuration::BASE_URL; ?>">Home</a>
</li>
<li><a <?php if ($FoundRoute['Controller'] == 'Overview') echo
'class="active";'?> href="<?php echo Configuration::BASE_URL; ?
>overview">Overview</a></li>
</ul>
it has more tabs, but you get the point.
I had to use this function that chooses the controller that will decide if the page is active or not. basically: If i'm on a page Overview, the script asks if the active Controller is named 'Overview' and if it is, it will select the tab as class="active".
However, this is wrong: my teacher said I can't have scripts in my view files (it's not wrong, it's just bad practice) and I need another method of doing this:
So, I created a method class Misc.php with a function Misc::url:
public static function url($link, $text){
echo '<a href="' . Configuration::BASE_URL . $link . '">' . $text .
'</a>';
}
this way my menu-session can just be:
<ul>
<li>Misc::url('', 'Home')</li>
<li>Misc::url('overview', 'Overview')</li>
</ul>
Now: I need a correct function in Misc.php where I have the >>> $FoundRoute['Controller'] <<< if statement implanted, something like:
Misc::urlWithActive($link, $text){
if ($foundRoute['Controller] = *thiscontroller*) {
echo '<a href="' . Configuration::BASE_URL . $link . '">' . $text .
'</a>';
}
I actually don't know how to write that.
I Really hope you guys understand what I need to do here and help me.
I've tried to find a solution to this a few different times, but keep coming up empty on a working solution. Essentially, I'm trying to find a way to have a link that is either a "close" or a "back" link in functionality. The condition being IF the use just came from another page within the same site OR if the user came into this page from an external link (search engine or otherwise).
Here's a couple links for further explanation and examples of how its NOT working:
This link shows a "list" or archive of posts: http://hillsiderancho.com/care-ministries/
Once a user goes into one of those posts (http://hillsiderancho.com/care-ministries/celebrate-recovery/), the link in the top right should read "Back", and should simply act as the browser back button, to allow the user to go back to viewing the list of pages (or possibly some other page that lead them to this post).
The other use case would be if the user comes into the post from an external site, the button should read "Close" and then point the user to the list page, not a "browser back" function that takes them away from the site again. We'd like to keep them in the site and let them explore more from the same area.
This is the code I have in place, and the "Back" button has a different functionality in nearly all of the different posts in this section... seeming as though its never hitting the "else" condition, and only coming up with some other strange referrer URL. (I just noticed a typo on my href in the "else" condition, but either way, its not getting to that page either):
<div class="post-close-btn">
<?php
$previousPage = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$url = site_url();
if ($previousPage = $url){ ?>
<a href="<?php echo $_SERVER['HTTP_REFERER']; ?>" class="primaryBtn">
<div class="inner vAlign">
<span class="text">BACK</span>
</div>
</a>
<?php } else { ?>
<a href="/care-ministries/" class="primaryBtn">
<div class="inner vAlign">
<span class="text">Close</span>
</div>
</a>
<?php } ?>
Can anyone help with this?
You are setting the variable in your if statement, not checking its value.
if ($previousPage = $url)
should be:
if ($previousPage == $url)
Here's the code that ended up working, after getting my variable corrected (thanks Robyn Overstreet)
<?php
$previousPage = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$url = site_url();
$url = preg_replace('#^https?://#', '', $url);
if ($previousPage == $url){ ?>
<a href="javascript:history.back();" class="secondaryBtn">
<div class="inner vAlign">
<span class="text">BACK</span>
</div>
</a>
<?php } else { ?>
<a href="/care-ministries/" class="secondaryBtn">
<div class="inner vAlign">
<span class="text">Close</span>
</div>
</a>
<?php } ?>
Also, I found the bit I needed to fix the URL (and get it to match up) here: https://stackoverflow.com/a/9549893/4842348
And finally, I should note that my "if" statement href was pointing back to the site homepage (duh, thats what it was told to do) - so I swapped in a basic JS history.back() - that works just fine.
I am new to PHP and was writing a condition while making WordPress website. I have writing the correct tag syntax but when I am converting it into PHP echo then it is showing error.
Both the tags are present in the jsfiddle link below.
Jsfiddle link
Please let me know how to convert correct HTML code of the jsfiddle link to correct and working PHP code.
In wordpress we can write php code in header.php , footer.php etc. files which are under the directory wordpress/wp-content or wordpress/wp-admin etc.
But if we want to use php code after login in wordpress I mean in page, post , widget etc. wordpress can't recognize those php code ().
So, please explain in which file are you writing both code.
I'm damn sure that the code which is not working is inside the admin panel.
(Note : if you want to use condition through () inside admin panel (inside page,post etc.) ) you have to add a plugin like Exec-PHP (https://wordpress.org/plugins/exec-php/) or any other plugin which executes PHP code in posts, pages and text widgets.
May be this will help
You added something in last like
";}?>
These are no needed
<?php if (is_user_logged_in() ) {
echo "<a"; <?php if ( get_post_meta( get_the_id(), 'dysaniaselect', true ) == 'dysania-link' && get_option('dysania_gridgallery_targetblank') == "true") {
echo 'target="_blank"'; } ?> class="<?php echo( get_post_meta( get_the_id(), 'dysaniaselect', true ) ); ?> <?php echo 'clbx' . $id; ?>" data-title="<?php the_title(); ?>" data-rel="<?php echo ( get_post_meta( get_the_id(), 'dysaniaselect', true ) ) . 'clbx' . $id; ?>" href="<?php if (!empty($video)) { echo $video; } else { echo $imageurl; } ?>">
hi i need help with a small bit of code for my wordpress theme.
<a href="<?php echo $link; ?>">
<?php
global $post;
foreach(get_the_tags($post->ID) as $tag) {
echo ' <li>'.$tag->name.', </li>';
}
?>
</a>
the code
<?php echo $link; ?>
this is for a link of a website that is already on the page the link part works great the only issue is i want the links (tags that are being used as keywords/anchor text)to be seo friendly for outbound links
what changes are needed? feel free to spice the link up for seo :)
If you're wanting the same link for each of the tags, then this is a solution:
<ul>
<?php
global $post;
foreach( get_the_tags($post->ID) as $tag ) {
echo '<li>' . $tag->name . '</li>';
}
?>
</ul>
Please note: I've added the unordered list start and end elements as these were missing, these could also be ordered list start and ends.
EDIT:
to reflect your code changes.
The code still looks the same...I would assume it should look something like this: (and I could be completely wrong) :)
<?php
global $post;
foreach(get_the_tags($post->ID) as $tag) {
echo ' <li>'.$tag->name.'</li>';
}
?>
I'm trying to add a button to my site which links to the next page of posts. I'm looking for a way to add an HTML link to the button so it actually works.
http://codex.wordpress.org/Template_Tags/wp_link_pages
I believe that explains what I want, but I'm not having any luck trying to get those snippets to work.
My button looks like:
Next Page
How can I link the button to the next page function in Wordpress?
EDIT:
My problem is I can't figure out how to associate this code with a button.
There are two 'built-in' ways of doing this in Wordpress:
1) If you need access to the link as a PHP variable, try Using get_next_posts_link
<?php $nextLink = get_next_posts_link( $label , $max_pages ); ?>
<?php $previousLink = get_previous_posts_link( $label ); ?>
From here the links are stored in variables and you can do whatever you'd like with them.
2) Otherwise use these:
<?php next_posts_link( $label , $max_pages ); ?>
<?php previous_posts_link( $label ); ?>
Where $label is the name of the link ( "Next Page" in your case ) and $max_pages is the max number of pages (if you want a limit), that the link shows up on.
If you want to style these, without having to enclose them inside another DIV, use Wordpress Filters
function apply_my_next_link_style ( ){
return 'class="button"';
}
apply_filters( 'next_posts_link_attributes', 'apply_my_next_link_style' )
3) If you need even more control you can try this, from the source code for the above functions:
if ( !is_single() ) {
echo '<a href="' . next_posts( 0, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', "Next Page") . '</a>';
}
Also, I would suggest asking these types of questions over at wordpress.stackexchange.com
Is necesary Snippets , visit this and this solve
<?php next_posts_link('Older Posts'); ?>
<?php previous_posts_link('Newer Posts'); ?>