Ok, I'm going crazy over the_permalink() function. This is not going to be easy to explain the issue, but I will try. When I'm on the index page of my website(index.php), and when I click on a link that's in the footer section, it will take me to the recent post (single.php), and that is fine. However, when I start off on the index page(index.php), and when I use the navigation bar to navigate to a certain page(page.php)(which has the same layout as the index.php), and then, when I click the same link that's in the footer section it should take me to the recent post (single.php), but it is not. It's taking me to the current page(page.php) instead of single.php. Here is a snippet of my code:
The footer:
<div id="clear"></div>
<div id="video">
<!--<img src="<?php bloginfo('template_url'); ?>/images/video_03.png" alt="Video" border="0" width="263" height="193" title="Video" />-->
<iframe width="263" height="208" src="http://www.youtube.com/embed/WYc4ZOxRX-4?rel=0" frameborder="0" allowfullscreen></iframe>
</div><!-- end of video -->
<div id="weeklyadbox">
<p id="content"><img src="<?php bloginfo('template_url'); ?>/images/weeklyad.jpg" height="147" width="178" alt="Weekly Specials" border="0" title="Click to See Our Weekly Specials" /></p>
</div><!-- end of weeklyadbox -->
<div id="weathericon">
<img src="<?php bloginfo('template_url'); ?>/images/icons_03.png" border="0" alt="Weather Icon" title="See Weather" height="96" width="83" />
</div>
<div id="directionsicon">
<img src="<?php bloginfo('template_url'); ?>/images/icons_04.png" border="0" alt="Directions Icon" title="Get Directions" height="94" width="96" />
</div>
<div id="webcamicon">
<img src="<?php bloginfo('template_url'); ?>/images/icons_05.png" border="0" alt="Web Cam Icon" title="Web Cam" height="96" width="84" />
</div>
</div><!-- end of container -->
<div id="footer">
©<?php echo date("Y"); echo " "; bloginfo('name'); ?>
</div>
</div>
<?php wp_footer(); ?>
The_permalink() is fine when I'm in the index section, but not when I'm on a different page. I tried using echo get_permalink(53), and it worked, but what happens when a client goes in the dashboard and creates a new post? The new post will have a different post ID, and that link will not point out to the new post, but will point out to the old post that has an ID equals to 53.
If you need to see other code, please let me know!
Any advice? Thank you for your help!
It looks like you are using the_permalink() outside the WP loop. get_permalink() works outside "the loop" because you are explicitly passing the "Post ID" to the function.
Read this page explaining "the loop"
http://codex.wordpress.org/The_Loop
From looking at the snippet you posted that appears to be the problem.
I posted some sample "loop" code below:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php /** YOUR CODE HERE **/ ?>
<?php endwhile; else: ?>
<p><?php
_e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
I'm guessing you misunderstood the functionality of the "the_permalink" function. It must be used inside the loop, and it will give you the url to the current post that is being processed within the loop. If you want to have a link that will always point to your posts page, you could use something like:
<?php
if(get_option('show_on_front') == 'page')
echo get_permalink(get_option('page_for_posts'));
else
echo bloginfo('url');
?>
Related
We are using your Advanced Custom Fields plug-in which by default provides a custom field group called Flexible Content Template. I'm trying to develop a new webpage with a new group of custom fields that is created only for this page named B2B landing page. A couple of sections in this page can be created by using an existing layouts called "Icon Columns" and "text and full image" from Flexible Content Template custom fields group. Question is how can I access the contents of these two layouts separately in the template file so that they are displayed when I need them to? Why I'm asking this is because in our project I see that we display flexible content field data with this line <?php get_template_part('template-parts/fields/field--flex-content'); ?> This brings contents from the Flexible Content field everywhere you call this function, not just the specific layout data meant for the section. I need to be able to display contents selectively. Below is the code for you to have a look and see if you can suggest some solution.
<!-- START HERO -->
<?php
$hero = get_field('hero');
$hero_h1 = $hero['hero_-_h1'];
$hero_h2 = $hero['hero_-_h2'];
$background = $hero['hero_-_background_options'];
$image = $background['background_-_image'];
$link = $hero['cta'];
?>
<?php get_header(); ?>
<div class="corp-hero relative mb-row">
<?php if($image): ?>
<div class="corp-hero-img relative no-touch select-none">
<picture>
<source media="(max-width: 480px)" srcset="<?php echo($image['sizes']['small']); ?>">
<source media="(max-width: 1024px)" srcset="<?php echo($image['sizes']['medium']); ?>">
<source media="(max-width: 1280px)" srcset="<?php echo($image['sizes']['large']); ?>">
<source srcset="<?php echo($image['sizes']['xlarge']); ?>">
<img src="<?php echo($image['sizes']['xlarge']); ?>" alt="<?php echo $image['alt']; ?>" />
</picture>
</div>
<?php endif; ?>
<div class="wrap-x">
<div class="inside">
<?php if(stripos($hero_h1, "Do Not Display") === FALSE): ?>
<h1 class="mb0 color-tan-dark">
<?php if( $hero_h1 ): echo $hero_h1; else: echo get_the_title(); endif; ?>
</h1>
<?php endif; ?>
<?php if( $hero_h2 ): ?>
<h2 class="mb0 mt2 alt-heading h4">
<?php echo $hero_h2; ?>
</h2>
<?php endif; ?>
</div>
</div>
<?php if ( $link ) : ?>
<div class="inside mt2x">
<div class="center-xs">
<a href="<?php echo $link['url']; ?>" class="btn cta-btn-purple" role="button" target="<?php echo $link['target']; ?>" title="<?php echo $link['title']; ?>">
<?php echo $link['title']; ?>
</a>
</div>
</div>
<?php endif; ?>
</div>
<!-- END HERO -->
<!-- START FAST, EASY ORDERING SECTION -->
// I need to only display contents from 'icon-columns' layout
<?php get_template_part('template-parts/fields/field--flex-content'); ?>
<!-- END FAST, EASY ORDERING SECTION -->
<!-- START HOW OUR GIFTS MAKE A SIGNIFICANT IMPACT Section -->
// I need to only display contents from 'text and full image' layout
<?php get_template_part('template-parts/fields/field--flex-content'); ?>
<!-- END HOW OUR GIFTS MAKE A SIGNIFICANT IMPACT Section -->
I am just learning Drupal and I am having trouble to display a logo on my custom theme..
page.tpl.php:
<a href="<?php print $front_page;?>">
<img src="/<?php print $directory;?>/img/logo.png" alt="<?php print $site_name;?>" height="80"
width="150" />
</a>
As I look inspecter, I see that the path is correct:
<img src="/themes/bony/img/logo.png" alt="Haldun Atar Drupal Page" height="80" width="150">
On Appearance > Settings panel I also entered the path: themes/bony/img/logo.png
I just can't display the logo.. Where do I search the problem?
P.s: I have the logo img in img file.
Thank you in advance!
If you uploaded the file on the theme settings page, you should have a $logo variable in the page.tpl.php (though this will depend on if you have overridden the preprocess).
You can see how it is output if you look in the 'modules/system/page.tpl.php'.
In the system page.tpl.php it is output like this:
<?php if ($logo): ?>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
If you click on the src link in inspector does it take you to the image? If not try an absolute path like /<absolute>/<path>/<to>/<your>/<folder>.
Did you clear cache after you made the changes?
Admin -> configuration -> performance -> clear cache
I'm using Wordpress Canyon Theme in my website (http://thomasconti.blog.br/). The slider works fine but it would be really great if it also showed post titles and in larger letters, instead of just a bunch of small text like the default configuration is set to show.
Please, if anyone can help, here is the code for the slider:
<?php get_header(); ?>
<div id="content">
<div id="slide">
<div class="flexslider">
<ul class="slides">
<?php
$slide = get_option('cany_slide_cat');
$count = get_option('cany_slide_count');
$slide_query = new WP_Query('category_name='.$slide.'&posts_per_page='.$count.'' );
while ( $slide_query->have_posts() ) : $slide_query->the_post();
$do_not_duplicate[] = $post->ID
?>
<li>
<img class="slideimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php echo get_image_url()?>&h=300&w=650&zc=1" title="" alt="" />
<div class="flex-caption">
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
I tried to find this info on the web but only found other bloggers using this theme and asking the same question. Thanks in advance for any help.
I don't know that plugin but from your question I'd say you need to put a wordpress template tags for the title in here:
<div class="flex-caption">
<!-- at this place -->
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
E.g. mock that with some dummy HTML and headlien:
<div class="flex-caption">
<h2>This is My Headline that is Just There</h2>
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
Style it via your themes CSS and for the content use the_title():
<div class="flex-caption">
<?php the_title( '<h2>', '</h2>' ); ?>
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
Depending on your styling needs you might want to introduce more markup.
To link the title you use the_permalink() again as you already have in your code. That could do it, so hopefully this gives you some pointers.
I created my own author.php template. I want to display author's custom meta fields Code samples is in this image : http://prntscr.com/wsdsa
But Wordpress doesnt display anything ? What should i do ?
<div class="BCol">
<?php echo keepAuthorImage(); ?>
</div>
<div class="ACol">
<div class="A1"><?php echo get_the_author_meta('first_name') ?> <?php echo get_the_author_meta('last_name') ?></div>
<div class="A2"><?php echo the_author_meta('job') ?></div>
<div class="A3"><?php echo get_the_author_meta('location') ?></div>
<div class="A5">
<img src="<?php echo THEME; ?>/_assets/_img/websiteicon.png" alt="">
<img src="<?php echo THEME; ?>/_assets/_img/twitteric.png" alt="">
<img src="<?php echo THEME; ?>/_assets/_img/instagramic.png" alt="">
</div>
<div class="A4"><?php echo get_the_author_meta('aboute') ?></div>
</div>
Any helps ? Thanks.
Wordpress have pre defined variables, as
$cat
$tag
etc.
you have to use
$author
to make your process.
what you are doing wrong is you are not using your get_the_author_meta() function in side the loop so you need to specify the author id.
either use the function in side your loop or use simple as below code
<?php
global $current_user;
$current_user = wp_get_current_user();
$uid=$current_user->ID;
?>
change your function author meta as
<?php echo get_the_author_meta('first_name',$uid) ?>
for all your author meta for more help you can check reference code http://codex.wordpress.org/Function_Reference/get_the_author_meta
I am using the ACF purely so the user can upload images to a predefined location and have assigned the page rules accordingly. Everything seems to be fine on the WP back-end, with the three images uploaded to the fields. However, on the font end, nothing apart from blank box is appearing at all where the images should be. Looking at the source that WP is outputting, there is only blank code:
<img src="" class="middle" alt="image1"/>
This is the loop I am using:
<?php query_posts("posts_per_page=1&post_type=page&page_id=168"); if (have_posts()) :
while ( have_posts() ) :
the_post(); ?>
<!--If you want to refer to the child of parent page, use "post_parent=" -->
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<img src="<?php the_field('image_1'); ?>" class="middle" alt="image1"/>
View More
</li>
<?php endwhile; ?>
<!-- post navigation -->
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>
<?php wp_reset_query(); ?>
It is important to note that I am not pulling the images from another page. I just want the images to relate to the template & page I am working on.
Make sure the image field is outputting the id or url of the image link.
<?php if(get_field('YOUR FIELD NAME')): while(has_sub_field('YOUR FIELD NAME')): ?>
<img class="logo" src="<?php the_sub_field('image_1'); ?>" />
<?php endwhile; endif; ?>
I just needed to nominate the home page id the function:
<img src="<?php the_field('image_2', '245'); ?>" class="middle" alt="image2"/>
you can use get_the_field() to get the right value of the field,
<img src="<?php get_the_field('image_1'); ?>" class="middle" alt="image1"/>